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