hotspot/test/gc/arguments/TestG1ConcMarkStepDurationMillis.java
author sangheki
Mon, 05 Oct 2015 14:56:19 -0700
changeset 33144 c56850e328fc
parent 32601 c5df671276bd
child 36851 03e2f4d0a421
permissions -rw-r--r--
8134995: [REDO] GC: implement ranges (optionally constraints) for those flags that have them missing Summary: Add ranges and constraint functions for GC flags. Reviewed-by: kbarrett, jmasa, jwilhelm, gziemski, zmajo
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
32601
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
     1
/*
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
     2
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
     3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
     4
*
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
     5
* This code is free software; you can redistribute it and/or modify it
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
     6
* under the terms of the GNU General Public License version 2 only, as
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
     7
* published by the Free Software Foundation.
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
     8
*
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
     9
* This code is distributed in the hope that it will be useful, but WITHOUT
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    11
* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    12
* version 2 for more details (a copy is included in the LICENSE file that
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    13
* accompanied this code).
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    14
*
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    15
* You should have received a copy of the GNU General Public License version
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    16
* 2 along with this work; if not, write to the Free Software Foundation,
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    18
*
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    20
* or visit www.oracle.com if you need additional information or have any
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    21
* questions.
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    22
*/
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    23
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    24
/*
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    25
 * @test TestG1ConcMarkStepDurationMillis
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    26
 * @key gc
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    27
 * @requires vm.gc=="null" | vm.gc=="G1"
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    28
 * @summary Tests argument processing for double type flag, G1ConcMarkStepDurationMillis
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    29
 * @library /testlibrary
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    30
 * @modules java.base/sun.misc
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    31
 *          java.management
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    32
 */
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    33
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    34
import jdk.test.lib.*;
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    35
import java.util.*;
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    36
import java.util.regex.*;
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    37
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    38
public class TestG1ConcMarkStepDurationMillis {
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    39
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    40
  static final int PASS                = 0;
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    41
  static final int FAIL_IMPROPER_VALUE = 1;
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    42
  static final int FAIL_OUT_RANGE      = 2;
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    43
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    44
  static final String DOUBLE_1       = "1.0";
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    45
  static final String DOUBLE_MAX     = "1.79e+308";
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    46
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    47
  static final String DOUBLE_NEG_EXP = "1.0e-30";
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    48
  static final String NEG_DOUBLE_1   = "-1.0";
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    49
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    50
  static final String DOUBLE_INF     = "1.79e+309";
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    51
  static final String NEG_DOUBLE_INF = "-1.79e+309";
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    52
  static final String DOUBLE_NAN     = "abe+309";
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    53
  static final String WRONG_DOUBLE_1 = "1.79e+308e";
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    54
  static final String WRONG_DOUBLE_2 = "1.79ee+308";
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    55
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    56
  public static void main(String args[]) throws Exception {
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    57
    // Pass cases
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    58
    runG1ConcMarkStepDurationMillisTest(DOUBLE_1,       PASS);
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    59
    runG1ConcMarkStepDurationMillisTest(DOUBLE_MAX,     PASS);
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    60
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    61
    // Fail cases: out of range
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    62
    runG1ConcMarkStepDurationMillisTest(DOUBLE_NEG_EXP, FAIL_OUT_RANGE);
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    63
    runG1ConcMarkStepDurationMillisTest(NEG_DOUBLE_1,   FAIL_OUT_RANGE);
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    64
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    65
    // Fail cases: not double
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    66
    runG1ConcMarkStepDurationMillisTest(DOUBLE_INF,     FAIL_IMPROPER_VALUE);
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    67
    runG1ConcMarkStepDurationMillisTest(NEG_DOUBLE_INF, FAIL_IMPROPER_VALUE);
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    68
    runG1ConcMarkStepDurationMillisTest(DOUBLE_NAN,     FAIL_IMPROPER_VALUE);
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    69
    runG1ConcMarkStepDurationMillisTest(WRONG_DOUBLE_1, FAIL_IMPROPER_VALUE);
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    70
    runG1ConcMarkStepDurationMillisTest(WRONG_DOUBLE_2, FAIL_IMPROPER_VALUE);
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    71
  }
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    72
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    73
  private static void runG1ConcMarkStepDurationMillisTest(String expectedValue, int expectedResult) throws Exception {
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    74
    List<String> vmOpts = new ArrayList<>();
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    75
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    76
    Collections.addAll(vmOpts, "-XX:+UseG1GC", "-XX:G1ConcMarkStepDurationMillis="+expectedValue, "-XX:+PrintFlagsFinal", "-version");
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    77
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    78
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(vmOpts.toArray(new String[vmOpts.size()]));
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    79
    OutputAnalyzer output = new OutputAnalyzer(pb.start());
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    80
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    81
    output.shouldHaveExitValue(expectedResult == PASS ? 0 : 1);
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    82
    String stdout = output.getStdout();
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    83
    if (expectedResult == PASS) {
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    84
      checkG1ConcMarkStepDurationMillisConsistency(stdout, expectedValue);
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    85
    } else if (expectedResult == FAIL_IMPROPER_VALUE) {
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    86
      output.shouldContain("Improperly specified VM option");
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    87
    } else if (expectedResult == FAIL_OUT_RANGE) {
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    88
      output.shouldContain("outside the allowed range");
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    89
    }
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    90
  }
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    91
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    92
  private static void checkG1ConcMarkStepDurationMillisConsistency(String output, String expectedValue) {
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    93
    double actualValue = getDoubleValue("G1ConcMarkStepDurationMillis", output);
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    94
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    95
    if (Double.parseDouble(expectedValue) != actualValue) {
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    96
      throw new RuntimeException(
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    97
            "Actual G1ConcMarkStepDurationMillis(" + Double.toString(actualValue)
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    98
            + ") is not equal to expected value(" + expectedValue + ")");
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
    99
    }
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
   100
  }
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
   101
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
   102
  public static double getDoubleValue(String flag, String where) {
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
   103
    Matcher m = Pattern.compile(flag + "\\s+:?=\\s+\\d+").matcher(where);
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
   104
    if (!m.find()) {
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
   105
      throw new RuntimeException("Could not find value for flag " + flag + " in output string");
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
   106
    }
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
   107
    String match = m.group();
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
   108
    return Double.parseDouble(match.substring(match.lastIndexOf(" ") + 1, match.length()));
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
   109
  }
c5df671276bd 8078555: GC: implement ranges (optionally constraints) for those flags that have them missing
sangheki
parents:
diff changeset
   110
}