test/hotspot/jtreg/gc/arguments/TestMaxHeapSizeTools.java
author lkorinth
Mon, 28 Jan 2019 15:53:56 +0100
changeset 53523 4c5184c56dc2
parent 47216 71c04702a3d5
child 55308 871bc449ce06
child 58678 9cf78a70fa4f
permissions -rw-r--r--
8214799: Add package declaration to each JTREG test case in the gc folder Reviewed-by: lmesnik, tschatzl
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);
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    58
  }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    59
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    60
  public static void checkMinInitialErgonomics(String gcflag) throws Exception {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    61
    // heap sizing ergonomics use the value NewSize + OldSize as default values
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    62
    // for ergonomics calculation. Retrieve these values.
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    63
    long[] values = new long[2];
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    64
    getNewOldSize(gcflag, values);
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    65
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    66
    // we check cases with values smaller and larger than this default value.
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    67
    long newPlusOldSize = values[0] + values[1];
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    68
    long smallValue = newPlusOldSize / 2;
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    69
    long largeValue = newPlusOldSize * 2;
21561
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents: 17389
diff changeset
    70
    long maxHeapSize = largeValue + (2 * 1024 * 1024);
17389
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    71
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    72
    // -Xms is not set
21561
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents: 17389
diff changeset
    73
    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
    74
    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
    75
    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
    76
    checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-XX:InitialHeapSize=0" }, values, -1, -1);
17389
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    77
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    78
    // -Xms is set to zero
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, "-Xms0" }, values, -1, -1);
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=" + smallValue }, values, -1, smallValue);
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents: 17389
diff changeset
    81
    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
    82
    checkErgonomics(new String[] { gcflag, "-Xmx" + maxHeapSize, "-Xms0", "-XX:InitialHeapSize=0" }, values, -1, -1);
17389
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    83
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    84
    // -Xms is set to small value
21561
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 }, values, -1, -1);
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=" + smallValue }, values, smallValue, smallValue);
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents: 17389
diff changeset
    87
    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
    88
    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
    89
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    90
    // -Xms is set to large value
21561
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents: 17389
diff changeset
    91
    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
    92
    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
    93
  }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    94
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    95
  private static long align_up(long value, long alignment) {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    96
    long alignmentMinusOne = alignment - 1;
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    97
    return (value + alignmentMinusOne) & ~alignmentMinusOne;
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    98
  }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
    99
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   100
  private static void getNewOldSize(String gcflag, long[] values) throws Exception {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   101
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(gcflag,
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   102
      "-XX:+PrintFlagsFinal", "-version");
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   103
    OutputAnalyzer output = new OutputAnalyzer(pb.start());
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   104
    output.shouldHaveExitValue(0);
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   105
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   106
    String stdout = output.getStdout();
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   107
    values[0] = getFlagValue(" NewSize", stdout);
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   108
    values[1] = getFlagValue(" OldSize", stdout);
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   109
  }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   110
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   111
  public static void checkGenMaxHeapErgo(String gcflag) throws Exception {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   112
    TestMaxHeapSizeTools.checkGenMaxHeapSize(gcflag, 4);
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   113
    TestMaxHeapSizeTools.checkGenMaxHeapSize(gcflag, 5);
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   114
  }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   115
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   116
  private static void checkInvalidMinInitialHeapCombinations(String gcflag) throws Exception {
37088
2f2b21b4df00 8067768: Check for too small values for -Xmx
pliden
parents: 30604
diff changeset
   117
    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
   118
    expectError(new String[] { gcflag, "-Xms64M", "-XX:InitialHeapSize=32M", "-version" });
17389
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   119
  }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   120
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   121
  private static void checkValidMinInitialHeapCombinations(String gcflag) throws Exception {
37088
2f2b21b4df00 8067768: Check for too small values for -Xmx
pliden
parents: 30604
diff changeset
   122
    expectValid(new String[] { gcflag, "-XX:InitialHeapSize=1024K", "-version" });
17389
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   123
    expectValid(new String[] { gcflag, "-XX:InitialHeapSize=8M", "-Xms4M", "-version" });
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   124
    expectValid(new String[] { gcflag, "-Xms4M", "-XX:InitialHeapSize=8M", "-version" });
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   125
    expectValid(new String[] { gcflag, "-XX:InitialHeapSize=8M", "-Xms8M", "-version" });
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   126
    // 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
   127
    expectValid(new String[] { gcflag, "-XX:InitialHeapSize=4M", "-Xms8M", "-version" });
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   128
  }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   129
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   130
  private static void checkInvalidInitialMaxHeapCombinations(String gcflag) throws Exception {
37088
2f2b21b4df00 8067768: Check for too small values for -Xmx
pliden
parents: 30604
diff changeset
   131
    expectError(new String[] { gcflag, "-XX:MaxHeapSize=2047K", "-version" });
17389
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   132
    expectError(new String[] { gcflag, "-XX:MaxHeapSize=4M", "-XX:InitialHeapSize=8M", "-version" });
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   133
    expectError(new String[] { gcflag, "-XX:InitialHeapSize=8M", "-XX:MaxHeapSize=4M", "-version" });
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   134
  }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   135
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   136
  private static void checkValidInitialMaxHeapCombinations(String gcflag) throws Exception {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   137
    expectValid(new String[] { gcflag, "-XX:InitialHeapSize=4M", "-XX:MaxHeapSize=8M", "-version" });
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   138
    expectValid(new String[] { gcflag, "-XX:MaxHeapSize=8M", "-XX:InitialHeapSize=4M", "-version" });
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   139
    expectValid(new String[] { gcflag, "-XX:MaxHeapSize=4M", "-XX:InitialHeapSize=4M", "-version" });
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   140
    // a value of "0" for initial heap size means auto-detect
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   141
    expectValid(new String[] { gcflag, "-XX:MaxHeapSize=4M", "-XX:InitialHeapSize=0M", "-version" });
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   142
  }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   143
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   144
  private static long valueAfter(String source, String match) {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   145
    int start = source.indexOf(match) + match.length();
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   146
    String tail = source.substring(start).split(" ")[0];
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   147
    return Long.parseLong(tail);
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   148
  }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   149
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   150
  /**
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   151
   * Executes a new VM process with the given class and parameters.
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   152
   * @param vmargs Arguments to the VM to run
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   153
   * @param classname Name of the class to run
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   154
   * @param arguments Arguments to the class
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   155
   * @param useTestDotJavaDotOpts Use test.java.opts as part of the VM argument string
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   156
   * @return The OutputAnalyzer with the results for the invocation.
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   157
   */
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   158
  public static OutputAnalyzer runWhiteBoxTest(String[] vmargs, String classname, String[] arguments, boolean useTestDotJavaDotOpts) throws Exception {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   159
    ArrayList<String> finalargs = new ArrayList<String>();
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   160
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   161
    String[] whiteboxOpts = new String[] {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   162
      "-Xbootclasspath/a:.",
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   163
      "-XX:+UnlockDiagnosticVMOptions", "-XX:+WhiteBoxAPI",
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   164
      "-cp", System.getProperty("java.class.path"),
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   165
    };
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   166
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   167
    if (useTestDotJavaDotOpts) {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   168
      // System.getProperty("test.java.opts") is '' if no options is set,
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   169
      // we need to skip such a result
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   170
      String[] externalVMOpts = new String[0];
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   171
      if (System.getProperty("test.java.opts") != null && System.getProperty("test.java.opts").length() != 0) {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   172
        externalVMOpts = System.getProperty("test.java.opts").split(" ");
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   173
      }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   174
      finalargs.addAll(Arrays.asList(externalVMOpts));
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   175
    }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   176
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   177
    finalargs.addAll(Arrays.asList(vmargs));
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   178
    finalargs.addAll(Arrays.asList(whiteboxOpts));
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   179
    finalargs.add(classname);
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   180
    finalargs.addAll(Arrays.asList(arguments));
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   181
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   182
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(finalargs.toArray(new String[0]));
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   183
    OutputAnalyzer output = new OutputAnalyzer(pb.start());
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   184
    output.shouldHaveExitValue(0);
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   185
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   186
    return output;
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   187
  }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   188
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   189
  private static void getMinInitialMaxHeap(String[] args, MinInitialMaxValues val) throws Exception {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   190
    OutputAnalyzer output = runWhiteBoxTest(args, ErgoArgsPrinter.class.getName(), new String[] {}, false);
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   191
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   192
    // the output we watch for has the following format:
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   193
    //
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   194
    // "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
   195
    //
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   196
    // where A, B, X, Y and Z are sizes in bytes.
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   197
    // Unfortunately there is no other way to retrieve the minimum heap size and
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   198
    // the alignments.
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   199
22765
cae8833b9e29 8028254: gc/arguments/TestMinInitialErgonomics.java failed with unexpected initial heap size
ehelin
parents: 21561
diff changeset
   200
    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
   201
      matcher(output.getStdout());
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   202
    if (!m.find()) {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   203
      throw new RuntimeException("Could not find heap size string.");
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   204
    }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   205
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   206
    String match = m.group();
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   207
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   208
    // actual values
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   209
    val.minHeapSize = valueAfter(match, "Minimum heap ");
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   210
    val.initialHeapSize = valueAfter(match, "Initial heap ");
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   211
    val.maxHeapSize = valueAfter(match, "Maximum heap ");
22765
cae8833b9e29 8028254: gc/arguments/TestMinInitialErgonomics.java failed with unexpected initial heap size
ehelin
parents: 21561
diff changeset
   212
    val.spaceAlignment = valueAfter(match, "Space alignment ");
cae8833b9e29 8028254: gc/arguments/TestMinInitialErgonomics.java failed with unexpected initial heap size
ehelin
parents: 21561
diff changeset
   213
    val.heapAlignment = valueAfter(match, "Heap alignment ");
17389
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   214
  }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   215
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   216
  /**
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   217
   * Verify whether the VM automatically synchronizes minimum and initial heap size if only
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   218
   * one is given for the GC specified.
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   219
   */
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   220
  public static void checkErgonomics(String[] args, long[] newoldsize,
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   221
    long expectedMin, long expectedInitial) throws Exception {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   222
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   223
    MinInitialMaxValues v = new MinInitialMaxValues();
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   224
    getMinInitialMaxHeap(args, v);
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   225
22765
cae8833b9e29 8028254: gc/arguments/TestMinInitialErgonomics.java failed with unexpected initial heap size
ehelin
parents: 21561
diff changeset
   226
    if ((expectedMin != -1) && (align_up(expectedMin, v.heapAlignment) != v.minHeapSize)) {
17389
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   227
      throw new RuntimeException("Actual minimum heap size of " + v.minHeapSize +
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   228
        " differs from expected minimum heap size of " + expectedMin);
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   229
    }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   230
22765
cae8833b9e29 8028254: gc/arguments/TestMinInitialErgonomics.java failed with unexpected initial heap size
ehelin
parents: 21561
diff changeset
   231
    if ((expectedInitial != -1) && (align_up(expectedInitial, v.heapAlignment) != v.initialHeapSize)) {
17389
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   232
      throw new RuntimeException("Actual initial heap size of " + v.initialHeapSize +
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   233
        " differs from expected initial heap size of " + expectedInitial);
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   234
    }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   235
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   236
    // always check the invariant min <= initial <= max heap size
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   237
    if (!(v.minHeapSize <= v.initialHeapSize && v.initialHeapSize <= v.maxHeapSize)) {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   238
      throw new RuntimeException("Inconsistent min/initial/max heap sizes, they are " +
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   239
        v.minHeapSize + "/" + v.initialHeapSize + "/" + v.maxHeapSize);
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
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   243
  /**
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   244
   * Verify whether the VM respects the given maximum heap size in MB for the
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   245
   * GC specified.
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   246
   * @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
   247
   * @param maxHeapSize the maximum heap size to verify, in MB.
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   248
   */
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   249
  public static void checkGenMaxHeapSize(String gcflag, long maxHeapsize) throws Exception {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   250
    final long K = 1024;
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   251
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   252
    MinInitialMaxValues v = new MinInitialMaxValues();
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   253
    getMinInitialMaxHeap(new String[] { gcflag, "-XX:MaxHeapSize=" + maxHeapsize + "M" }, v);
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   254
22765
cae8833b9e29 8028254: gc/arguments/TestMinInitialErgonomics.java failed with unexpected initial heap size
ehelin
parents: 21561
diff changeset
   255
    long expectedHeapSize = align_up(maxHeapsize * K * K, v.heapAlignment);
17389
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   256
    long actualHeapSize = v.maxHeapSize;
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   257
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   258
    if (actualHeapSize > expectedHeapSize) {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   259
      throw new RuntimeException("Heap has " + actualHeapSize  +
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   260
        " bytes, expected to be less than " + expectedHeapSize);
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   261
    }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   262
  }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   263
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   264
  private static long getFlagValue(String flag, String where) {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   265
    Matcher m = Pattern.compile(flag + "\\s+:?=\\s+\\d+").matcher(where);
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   266
    if (!m.find()) {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   267
      throw new RuntimeException("Could not find value for flag " + flag + " in output string");
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   268
    }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   269
    String match = m.group();
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   270
    return Long.parseLong(match.substring(match.lastIndexOf(" ") + 1, match.length()));
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   271
  }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   272
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   273
  private static void shouldContainOrNot(OutputAnalyzer output, boolean contains, String message) throws Exception {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   274
    if (contains) {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   275
      output.shouldContain(message);
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   276
    } else {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   277
      output.shouldNotContain(message);
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   278
    }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   279
  }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   280
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   281
  private static void expect(String[] flags, boolean hasWarning, boolean hasError, int errorcode) throws Exception {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   282
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(flags);
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   283
    OutputAnalyzer output = new OutputAnalyzer(pb.start());
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   284
    shouldContainOrNot(output, hasWarning, "Warning");
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   285
    shouldContainOrNot(output, hasError, "Error");
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   286
    output.shouldHaveExitValue(errorcode);
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   287
  }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   288
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   289
  private static void expectError(String[] flags) throws Exception {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   290
    expect(flags, false, true, 1);
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   291
  }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   292
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   293
  private static void expectValid(String[] flags) throws Exception {
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   294
    expect(flags, false, false, 0);
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   295
  }
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   296
}
25ba661e4352 8014058: Regression tests for 8006088
tschatzl
parents:
diff changeset
   297