test/hotspot/jtreg/gc/arguments/TestMaxHeapSizeTools.java
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 55621 ea3b1a8fd4bb
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17389
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
     1
/*
53523
4c5184c56dc2 8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents: 47216
diff changeset
     2
 * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
41705
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40631
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40631
diff changeset
     4
 *
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40631
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40631
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40631
diff changeset
     7
 * published by the Free Software Foundation.
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40631
diff changeset
     8
 *
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40631
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40631
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40631
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40631
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40631
diff changeset
    13
 * accompanied this code).
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40631
diff changeset
    14
 *
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40631
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40631
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40631
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40631
diff changeset
    18
 *
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40631
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40631
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40631
diff changeset
    21
 * questions.
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40631
diff changeset
    22
 */
17389
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    23
53523
4c5184c56dc2 8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents: 47216
diff changeset
    24
package gc.arguments;
4c5184c56dc2 8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents: 47216
diff changeset
    25
17389
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    26
import java.util.regex.Matcher;
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    27
import java.util.regex.Pattern;
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    28
import java.util.ArrayList;
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    29
import java.util.Arrays;
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    30
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 39993
diff changeset
    31
import jdk.test.lib.process.ProcessTools;
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 39993
diff changeset
    32
import jdk.test.lib.process.OutputAnalyzer;
17389
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    33
import sun.hotspot.WhiteBox;
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    34
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    35
class ErgoArgsPrinter {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    36
  public static void main(String[] args) throws Exception {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    37
    WhiteBox wb = WhiteBox.getWhiteBox();
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    38
    wb.printHeapSizes();
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    39
  }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    40
}
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    41
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    42
final class MinInitialMaxValues {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    43
  public long minHeapSize;
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    44
  public long initialHeapSize;
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    45
  public long maxHeapSize;
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    46
22765
cae8833b9e29 8028254: gc/arguments/TestMinInitialErgonomics.java failed with unexpected initial heap size
ehelin
parents: 21561
diff changeset
    47
  public long spaceAlignment;
cae8833b9e29 8028254: gc/arguments/TestMinInitialErgonomics.java failed with unexpected initial heap size
ehelin
parents: 21561
diff changeset
    48
  public long heapAlignment;
17389
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    49
}
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    50
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    51
class TestMaxHeapSizeTools {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    52
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    53
  public static void checkMinInitialMaxHeapFlags(String gcflag) throws Exception {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    54
    checkInvalidMinInitialHeapCombinations(gcflag);
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    55
    checkValidMinInitialHeapCombinations(gcflag);
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    56
    checkInvalidInitialMaxHeapCombinations(gcflag);
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    57
    checkValidInitialMaxHeapCombinations(gcflag);
55308
871bc449ce06 8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents: 53523
diff changeset
    58
    checkInvalidMinMaxHeapCombinations(gcflag);
871bc449ce06 8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents: 53523
diff changeset
    59
    checkValidMinMaxHeapCombinations(gcflag);
17389
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    60
  }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    61
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    62
  public static void checkMinInitialErgonomics(String gcflag) throws Exception {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    63
    // heap sizing ergonomics use the value NewSize + OldSize as default values
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    64
    // for ergonomics calculation. Retrieve these values.
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    65
    long[] values = new long[2];
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    66
    getNewOldSize(gcflag, values);
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    67
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    68
    // we check cases with values smaller and larger than this default value.
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    69
    long newPlusOldSize = values[0] + values[1];
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    70
    long smallValue = newPlusOldSize / 2;
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    71
    long largeValue = newPlusOldSize * 2;
21561
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents: 17389
diff changeset
    72
    long maxHeapSize = largeValue + (2 * 1024 * 1024);
17389
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    73
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    74
    // -Xms is not set
21561
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents: 17389
diff changeset
    75
    checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize }, values, -1, -1);
55308
871bc449ce06 8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents: 53523
diff changeset
    76
    checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-XX:MinHeapSize=" + smallValue }, values, smallValue, -1);
871bc449ce06 8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents: 53523
diff changeset
    77
    checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-XX:MinHeapSize=" + largeValue }, values, largeValue, -1);
871bc449ce06 8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents: 53523
diff changeset
    78
    checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-XX:MinHeapSize=0" }, values, -1, -1);
21561
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents: 17389
diff changeset
    79
    checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-XX:InitialHeapSize=" + smallValue }, values, -1, smallValue);
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents: 17389
diff changeset
    80
    checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-XX:InitialHeapSize=" + largeValue }, values, -1, largeValue);
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents: 17389
diff changeset
    81
    checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-XX:InitialHeapSize=0" }, values, -1, -1);
55308
871bc449ce06 8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents: 53523
diff changeset
    82
    // Some extra checks when both are set.
871bc449ce06 8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents: 53523
diff changeset
    83
    checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-XX:MinHeapSize=" + smallValue, "-XX:InitialHeapSize=" + smallValue }, values, smallValue, smallValue);
871bc449ce06 8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents: 53523
diff changeset
    84
    checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-XX:MinHeapSize=" + smallValue, "-XX:InitialHeapSize=" + largeValue }, values, smallValue, largeValue);
871bc449ce06 8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents: 53523
diff changeset
    85
    checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-XX:MinHeapSize=" + largeValue, "-XX:InitialHeapSize=" + largeValue }, values, largeValue, largeValue);
17389
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    86
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    87
    // -Xms is set to zero
21561
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents: 17389
diff changeset
    88
    checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms0" }, values, -1, -1);
55308
871bc449ce06 8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents: 53523
diff changeset
    89
    checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms0", "-XX:MinHeapSize=" + smallValue }, values, smallValue, -1);
871bc449ce06 8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents: 53523
diff changeset
    90
    checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms0", "-XX:MinHeapSize=" + largeValue }, values, largeValue, -1);
871bc449ce06 8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents: 53523
diff changeset
    91
    checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms0", "-XX:MinHeapSize=0" }, values, -1, -1);
21561
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents: 17389
diff changeset
    92
    checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms0", "-XX:InitialHeapSize=" + smallValue }, values, -1, smallValue);
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents: 17389
diff changeset
    93
    checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms0", "-XX:InitialHeapSize=" + largeValue }, values, -1, largeValue);
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents: 17389
diff changeset
    94
    checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms0", "-XX:InitialHeapSize=0" }, values, -1, -1);
55308
871bc449ce06 8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents: 53523
diff changeset
    95
    checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms0", "-XX:MinHeapSize=" + smallValue, "-XX:InitialHeapSize=" + smallValue }, values, smallValue, smallValue);
871bc449ce06 8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents: 53523
diff changeset
    96
    checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms0", "-XX:MinHeapSize=" + smallValue, "-XX:InitialHeapSize=" + largeValue }, values, smallValue, largeValue);
871bc449ce06 8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents: 53523
diff changeset
    97
    checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms0", "-XX:MinHeapSize=" + largeValue, "-XX:InitialHeapSize=" + largeValue }, values, largeValue, largeValue);
17389
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    98
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    99
    // -Xms is set to small value
21561
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents: 17389
diff changeset
   100
    checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms" + smallValue }, values, -1, -1);
55308
871bc449ce06 8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents: 53523
diff changeset
   101
    checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms" + smallValue, "-XX:MinHeapSize=" + smallValue }, values, smallValue, smallValue);
871bc449ce06 8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents: 53523
diff changeset
   102
    checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms" + smallValue, "-XX:MinHeapSize=0" }, values, -1, smallValue);
21561
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents: 17389
diff changeset
   103
    checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms" + smallValue, "-XX:InitialHeapSize=" + smallValue }, values, smallValue, smallValue);
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents: 17389
diff changeset
   104
    checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms" + smallValue, "-XX:InitialHeapSize=" + largeValue }, values, smallValue, largeValue);
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents: 17389
diff changeset
   105
    checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms" + smallValue, "-XX:InitialHeapSize=0" }, values, smallValue, -1);
17389
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   106
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   107
    // -Xms is set to large value
21561
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents: 17389
diff changeset
   108
    checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms" + largeValue }, values, largeValue, largeValue);
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents: 17389
diff changeset
   109
    checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms" + largeValue, "-XX:InitialHeapSize=0" }, values, largeValue, -1);
55308
871bc449ce06 8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents: 53523
diff changeset
   110
    checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms" + largeValue, "-XX:MinHeapSize=0" }, values, -1, largeValue);
17389
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   111
  }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   112
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   113
  private static long align_up(long value, long alignment) {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   114
    long alignmentMinusOne = alignment - 1;
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   115
    return (value + alignmentMinusOne) & ~alignmentMinusOne;
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   116
  }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   117
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   118
  private static void getNewOldSize(String gcflag, long[] values) throws Exception {
55610
47fdb5b0fa41 8217170: gc/arguments/TestUseCompressedOopsErgo.java timed out
kbarrett
parents: 55308
diff changeset
   119
    ProcessBuilder pb = GCArguments.createJavaProcessBuilder(gcflag,
17389
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   120
      "-XX:+PrintFlagsFinal", "-version");
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   121
    OutputAnalyzer output = new OutputAnalyzer(pb.start());
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   122
    output.shouldHaveExitValue(0);
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   123
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   124
    String stdout = output.getStdout();
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   125
    values[0] = getFlagValue(" NewSize", stdout);
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   126
    values[1] = getFlagValue(" OldSize", stdout);
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   127
  }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   128
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   129
  public static void checkGenMaxHeapErgo(String gcflag) throws Exception {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   130
    TestMaxHeapSizeTools.checkGenMaxHeapSize(gcflag, 4);
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   131
    TestMaxHeapSizeTools.checkGenMaxHeapSize(gcflag, 5);
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   132
  }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   133
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   134
  private static void checkInvalidMinInitialHeapCombinations(String gcflag) throws Exception {
37088
2f2b21b4df00 8067768: Check for too small values for -Xmx
pliden
parents: 30604
diff changeset
   135
    expectError(new String[] { gcflag, "-XX:InitialHeapSize=1023K", "-version" });
28497
a7aecf0ffb6b 8067941: [TESTBUG] Fix tests for OS with 64K page size.
goetz
parents: 22765
diff changeset
   136
    expectError(new String[] { gcflag, "-Xms64M", "-XX:InitialHeapSize=32M", "-version" });
55308
871bc449ce06 8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents: 53523
diff changeset
   137
    expectError(new String[] { gcflag, "-XX:MinHeapSize=1023K", "-version" });
55618
978b2201984c 8226302: Test failures on IBM platforms (power and s/390) after JDK-8223837
mdoerr
parents: 55308
diff changeset
   138
    // Note: MinHeapSize values get aligned up by HeapAlignment which is 32M with 64k pages.
978b2201984c 8226302: Test failures on IBM platforms (power and s/390) after JDK-8223837
mdoerr
parents: 55308
diff changeset
   139
    expectError(new String[] { gcflag, "-Xms4M", "-XX:MinHeapSize=64M", "-version" });
55308
871bc449ce06 8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents: 53523
diff changeset
   140
    expectError(new String[] { gcflag, "-XX:MinHeapSize=8M -XX:InitialHeapSize=4m" });
17389
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   141
  }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   142
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   143
  private static void checkValidMinInitialHeapCombinations(String gcflag) throws Exception {
37088
2f2b21b4df00 8067768: Check for too small values for -Xmx
pliden
parents: 30604
diff changeset
   144
    expectValid(new String[] { gcflag, "-XX:InitialHeapSize=1024K", "-version" });
17389
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   145
    expectValid(new String[] { gcflag, "-XX:InitialHeapSize=8M", "-Xms4M", "-version" });
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   146
    expectValid(new String[] { gcflag, "-Xms4M", "-XX:InitialHeapSize=8M", "-version" });
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   147
    expectValid(new String[] { gcflag, "-XX:InitialHeapSize=8M", "-Xms8M", "-version" });
55308
871bc449ce06 8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents: 53523
diff changeset
   148
    expectValid(new String[] { gcflag, "-XX:MinHeapSize=1024K", "-version" });
871bc449ce06 8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents: 53523
diff changeset
   149
    expectValid(new String[] { gcflag, "-XX:MinHeapSize=8M", "-Xms4M", "-version" });
871bc449ce06 8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents: 53523
diff changeset
   150
    expectValid(new String[] { gcflag, "-XX:MinHeapSize=8M", "-Xms8M", "-version" });
871bc449ce06 8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents: 53523
diff changeset
   151
    expectValid(new String[] { gcflag, "-Xms8M", "-XX:MinHeapSize=4M", "-version" });
17389
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   152
    // the following is not an error as -Xms sets both minimal and initial heap size
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   153
    expectValid(new String[] { gcflag, "-XX:InitialHeapSize=4M", "-Xms8M", "-version" });
55308
871bc449ce06 8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents: 53523
diff changeset
   154
    expectValid(new String[] { gcflag, "-XX:MinHeapSize=4M", "-Xms8M", "-version" });
17389
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   155
  }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   156
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   157
  private static void checkInvalidInitialMaxHeapCombinations(String gcflag) throws Exception {
37088
2f2b21b4df00 8067768: Check for too small values for -Xmx
pliden
parents: 30604
diff changeset
   158
    expectError(new String[] { gcflag, "-XX:MaxHeapSize=2047K", "-version" });
17389
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   159
    expectError(new String[] { gcflag, "-XX:MaxHeapSize=4M", "-XX:InitialHeapSize=8M", "-version" });
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   160
    expectError(new String[] { gcflag, "-XX:InitialHeapSize=8M", "-XX:MaxHeapSize=4M", "-version" });
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   161
  }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   162
55308
871bc449ce06 8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents: 53523
diff changeset
   163
  private static void checkInvalidMinMaxHeapCombinations(String gcflag) throws Exception {
871bc449ce06 8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents: 53523
diff changeset
   164
    expectError(new String[] { gcflag, "-XX:MaxHeapSize=4M", "-XX:MinHeapSize=8M", "-version" });
871bc449ce06 8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents: 53523
diff changeset
   165
    expectError(new String[] { gcflag, "-XX:MinHeapSize=8M", "-XX:MaxHeapSize=4M", "-version" });
871bc449ce06 8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents: 53523
diff changeset
   166
  }
871bc449ce06 8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents: 53523
diff changeset
   167
871bc449ce06 8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents: 53523
diff changeset
   168
17389
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   169
  private static void checkValidInitialMaxHeapCombinations(String gcflag) throws Exception {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   170
    expectValid(new String[] { gcflag, "-XX:InitialHeapSize=4M", "-XX:MaxHeapSize=8M", "-version" });
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   171
    expectValid(new String[] { gcflag, "-XX:MaxHeapSize=8M", "-XX:InitialHeapSize=4M", "-version" });
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   172
    expectValid(new String[] { gcflag, "-XX:MaxHeapSize=4M", "-XX:InitialHeapSize=4M", "-version" });
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   173
    // a value of "0" for initial heap size means auto-detect
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   174
    expectValid(new String[] { gcflag, "-XX:MaxHeapSize=4M", "-XX:InitialHeapSize=0M", "-version" });
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   175
  }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   176
55308
871bc449ce06 8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents: 53523
diff changeset
   177
  private static void checkValidMinMaxHeapCombinations(String gcflag) throws Exception {
871bc449ce06 8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents: 53523
diff changeset
   178
    expectValid(new String[] { gcflag, "-XX:MinHeapSize=4M", "-XX:MaxHeapSize=8M", "-version" });
871bc449ce06 8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents: 53523
diff changeset
   179
    expectValid(new String[] { gcflag, "-XX:MaxHeapSize=8M", "-XX:MinHeapSize=4M", "-version" });
871bc449ce06 8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents: 53523
diff changeset
   180
    expectValid(new String[] { gcflag, "-XX:MaxHeapSize=4M", "-XX:MinHeapSize=4M", "-version" });
871bc449ce06 8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents: 53523
diff changeset
   181
    // a value of "0" for min heap size means auto-detect
871bc449ce06 8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents: 53523
diff changeset
   182
    expectValid(new String[] { gcflag, "-XX:MaxHeapSize=4M", "-XX:MinHeapSize=0M", "-version" });
871bc449ce06 8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents: 53523
diff changeset
   183
  }
871bc449ce06 8223837: Add -XX:MinHeapSize flag to set the minimum heap size
stefank
parents: 53523
diff changeset
   184
17389
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   185
  private static long valueAfter(String source, String match) {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   186
    int start = source.indexOf(match) + match.length();
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   187
    String tail = source.substring(start).split(" ")[0];
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   188
    return Long.parseLong(tail);
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   189
  }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   190
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   191
  /**
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   192
   * Executes a new VM process with the given class and parameters.
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   193
   * @param vmargs Arguments to the VM to run
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   194
   * @param classname Name of the class to run
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   195
   * @param arguments Arguments to the class
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   196
   * @param useTestDotJavaDotOpts Use test.java.opts as part of the VM argument string
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   197
   * @return The OutputAnalyzer with the results for the invocation.
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   198
   */
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   199
  public static OutputAnalyzer runWhiteBoxTest(String[] vmargs, String classname, String[] arguments, boolean useTestDotJavaDotOpts) throws Exception {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   200
    ArrayList<String> finalargs = new ArrayList<String>();
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   201
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   202
    String[] whiteboxOpts = new String[] {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   203
      "-Xbootclasspath/a:.",
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   204
      "-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI",
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   205
      "-cp", System.getProperty("java.class.path"),
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   206
    };
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   207
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   208
    if (useTestDotJavaDotOpts) {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   209
      // System.getProperty("test.java.opts") is '' if no options is set,
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   210
      // we need to skip such a result
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   211
      String[] externalVMOpts = new String[0];
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   212
      if (System.getProperty("test.java.opts") != null && System.getProperty("test.java.opts").length() != 0) {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   213
        externalVMOpts = System.getProperty("test.java.opts").split(" ");
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   214
      }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   215
      finalargs.addAll(Arrays.asList(externalVMOpts));
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   216
    }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   217
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   218
    finalargs.addAll(Arrays.asList(vmargs));
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   219
    finalargs.addAll(Arrays.asList(whiteboxOpts));
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   220
    finalargs.add(classname);
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   221
    finalargs.addAll(Arrays.asList(arguments));
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   222
55610
47fdb5b0fa41 8217170: gc/arguments/TestUseCompressedOopsErgo.java timed out
kbarrett
parents: 55308
diff changeset
   223
    ProcessBuilder pb = GCArguments.createJavaProcessBuilder(finalargs.toArray(new String[0]));
17389
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   224
    OutputAnalyzer output = new OutputAnalyzer(pb.start());
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   225
    output.shouldHaveExitValue(0);
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   226
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   227
    return output;
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   228
  }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   229
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   230
  private static void getMinInitialMaxHeap(String[] args, MinInitialMaxValues val) throws Exception {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   231
    OutputAnalyzer output = runWhiteBoxTest(args, ErgoArgsPrinter.class.getName(), new String[] {}, false);
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   232
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   233
    // the output we watch for has the following format:
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   234
    //
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   235
    // "Minimum heap X Initial heap Y Maximum heap Z Min alignment A Max Alignment B"
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   236
    //
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   237
    // where A, B, X, Y and Z are sizes in bytes.
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   238
    // Unfortunately there is no other way to retrieve the minimum heap size and
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   239
    // the alignments.
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   240
22765
cae8833b9e29 8028254: gc/arguments/TestMinInitialErgonomics.java failed with unexpected initial heap size
ehelin
parents: 21561
diff changeset
   241
    Matcher m = Pattern.compile("Minimum heap \\d+ Initial heap \\d+ Maximum heap \\d+ Space alignment \\d+ Heap alignment \\d+").
17389
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   242
      matcher(output.getStdout());
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   243
    if (!m.find()) {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   244
      throw new RuntimeException("Could not find heap size string.");
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   245
    }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   246
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   247
    String match = m.group();
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   248
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   249
    // actual values
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   250
    val.minHeapSize = valueAfter(match, "Minimum heap ");
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   251
    val.initialHeapSize = valueAfter(match, "Initial heap ");
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   252
    val.maxHeapSize = valueAfter(match, "Maximum heap ");
22765
cae8833b9e29 8028254: gc/arguments/TestMinInitialErgonomics.java failed with unexpected initial heap size
ehelin
parents: 21561
diff changeset
   253
    val.spaceAlignment = valueAfter(match, "Space alignment ");
cae8833b9e29 8028254: gc/arguments/TestMinInitialErgonomics.java failed with unexpected initial heap size
ehelin
parents: 21561
diff changeset
   254
    val.heapAlignment = valueAfter(match, "Heap alignment ");
17389
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   255
  }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   256
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   257
  /**
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   258
   * Verify whether the VM automatically synchronizes minimum and initial heap size if only
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   259
   * one is given for the GC specified.
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   260
   */
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   261
  public static void checkErgonomics(String[] args, long[] newoldsize,
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   262
    long expectedMin, long expectedInitial) throws Exception {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   263
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   264
    MinInitialMaxValues v = new MinInitialMaxValues();
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   265
    getMinInitialMaxHeap(args, v);
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   266
22765
cae8833b9e29 8028254: gc/arguments/TestMinInitialErgonomics.java failed with unexpected initial heap size
ehelin
parents: 21561
diff changeset
   267
    if ((expectedMin != -1) && (align_up(expectedMin, v.heapAlignment) != v.minHeapSize)) {
17389
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   268
      throw new RuntimeException("Actual minimum heap size of " + v.minHeapSize +
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   269
        " differs from expected minimum heap size of " + expectedMin);
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   270
    }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   271
22765
cae8833b9e29 8028254: gc/arguments/TestMinInitialErgonomics.java failed with unexpected initial heap size
ehelin
parents: 21561
diff changeset
   272
    if ((expectedInitial != -1) && (align_up(expectedInitial, v.heapAlignment) != v.initialHeapSize)) {
17389
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   273
      throw new RuntimeException("Actual initial heap size of " + v.initialHeapSize +
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   274
        " differs from expected initial heap size of " + expectedInitial);
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   275
    }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   276
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   277
    // always check the invariant min <= initial <= max heap size
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   278
    if (!(v.minHeapSize <= v.initialHeapSize && v.initialHeapSize <= v.maxHeapSize)) {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   279
      throw new RuntimeException("Inconsistent min/initial/max heap sizes, they are " +
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   280
        v.minHeapSize + "/" + v.initialHeapSize + "/" + v.maxHeapSize);
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   281
    }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   282
  }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   283
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   284
  /**
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   285
   * Verify whether the VM respects the given maximum heap size in MB for the
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   286
   * GC specified.
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   287
   * @param gcflag The garbage collector to test as command line flag. E.g. -XX:+UseG1GC
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   288
   * @param maxHeapSize the maximum heap size to verify, in MB.
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   289
   */
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   290
  public static void checkGenMaxHeapSize(String gcflag, long maxHeapsize) throws Exception {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   291
    final long K = 1024;
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   292
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   293
    MinInitialMaxValues v = new MinInitialMaxValues();
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   294
    getMinInitialMaxHeap(new String[] { gcflag, "-XX:MaxHeapSize=" + maxHeapsize + "M" }, v);
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   295
22765
cae8833b9e29 8028254: gc/arguments/TestMinInitialErgonomics.java failed with unexpected initial heap size
ehelin
parents: 21561
diff changeset
   296
    long expectedHeapSize = align_up(maxHeapsize * K * K, v.heapAlignment);
17389
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   297
    long actualHeapSize = v.maxHeapSize;
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   298
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   299
    if (actualHeapSize > expectedHeapSize) {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   300
      throw new RuntimeException("Heap has " + actualHeapSize  +
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   301
        " bytes, expected to be less than " + expectedHeapSize);
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   302
    }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   303
  }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   304
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   305
  private static long getFlagValue(String flag, String where) {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   306
    Matcher m = Pattern.compile(flag + "\\s+:?=\\s+\\d+").matcher(where);
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   307
    if (!m.find()) {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   308
      throw new RuntimeException("Could not find value for flag " + flag + " in output string");
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   309
    }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   310
    String match = m.group();
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   311
    return Long.parseLong(match.substring(match.lastIndexOf(" ") + 1, match.length()));
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   312
  }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   313
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   314
  private static void shouldContainOrNot(OutputAnalyzer output, boolean contains, String message) throws Exception {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   315
    if (contains) {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   316
      output.shouldContain(message);
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   317
    } else {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   318
      output.shouldNotContain(message);
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   319
    }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   320
  }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   321
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   322
  private static void expect(String[] flags, boolean hasWarning, boolean hasError, int errorcode) throws Exception {
55610
47fdb5b0fa41 8217170: gc/arguments/TestUseCompressedOopsErgo.java timed out
kbarrett
parents: 55308
diff changeset
   323
    ProcessBuilder pb = GCArguments.createJavaProcessBuilder(flags);
17389
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   324
    OutputAnalyzer output = new OutputAnalyzer(pb.start());
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   325
    shouldContainOrNot(output, hasWarning, "Warning");
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   326
    shouldContainOrNot(output, hasError, "Error");
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   327
    output.shouldHaveExitValue(errorcode);
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   328
  }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   329
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   330
  private static void expectError(String[] flags) throws Exception {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   331
    expect(flags, false, true, 1);
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   332
  }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   333
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   334
  private static void expectValid(String[] flags) throws Exception {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   335
    expect(flags, false, false, 0);
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   336
  }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   337
}