hotspot/test/gc/arguments/TestMaxNewSize.java
author pliden
Fri, 30 May 2014 10:37:39 +0200
changeset 24841 5fc47eabda8b
parent 21561 c619b1cb4554
child 29678 dd2f3932c21e
permissions -rw-r--r--
8044132: Quarantine unstable/broken GC tests Reviewed-by: ehelin, jwilhelm
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21561
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
     1
/*
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
     2
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
     3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
     4
*
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
     5
* This code is free software; you can redistribute it and/or modify it
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
     6
* under the terms of the GNU General Public License version 2 only, as
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
     7
* published by the Free Software Foundation.
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
     8
*
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
     9
* This code is distributed in the hope that it will be useful, but WITHOUT
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    11
* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    12
* version 2 for more details (a copy is included in the LICENSE file that
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    13
* accompanied this code).
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    14
*
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    15
* You should have received a copy of the GNU General Public License version
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    16
* 2 along with this work; if not, write to the Free Software Foundation,
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    18
*
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    20
* or visit www.oracle.com if you need additional information or have any
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    21
* questions.
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    22
*/
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    23
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    24
/*
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    25
 * @test TestMaxNewSize
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    26
 * @key gc
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    27
 * @bug 7057939
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    28
 * @summary Make sure that MaxNewSize always has a useful value after argument
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    29
 * processing.
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    30
 * @library /testlibrary
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    31
 * @build TestMaxNewSize
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    32
 * @run main TestMaxNewSize -XX:+UseSerialGC
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    33
 * @run main TestMaxNewSize -XX:+UseParallelGC
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    34
 * @run main TestMaxNewSize -XX:+UseConcMarkSweepGC
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    35
 * @run main TestMaxNewSize -XX:+UseG1GC
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    36
 * @author thomas.schatzl@oracle.com, jesper.wilhelmsson@oracle.com
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    37
 */
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    38
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    39
import java.util.regex.Matcher;
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    40
import java.util.regex.Pattern;
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    41
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    42
import java.math.BigInteger;
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    43
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    44
import java.util.ArrayList;
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    45
import java.util.Arrays;
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    46
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    47
import com.oracle.java.testlibrary.*;
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    48
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    49
public class TestMaxNewSize {
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    50
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    51
  private static void checkMaxNewSize(String[] flags, int heapsize) throws Exception {
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    52
    BigInteger actual = new BigInteger(getMaxNewSize(flags));
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    53
    System.out.println(actual);
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    54
    if (actual.compareTo(new BigInteger((new Long(heapsize)).toString())) == 1) {
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    55
      throw new RuntimeException("MaxNewSize value set to \"" + actual +
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    56
        "\", expected otherwise when running with the following flags: " + Arrays.asList(flags).toString());
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    57
    }
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    58
  }
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    59
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    60
  private static void checkIncompatibleNewSize(String[] flags) throws Exception {
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    61
    ArrayList<String> finalargs = new ArrayList<String>();
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    62
    finalargs.addAll(Arrays.asList(flags));
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    63
    finalargs.add("-version");
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    64
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    65
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(finalargs.toArray(new String[0]));
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    66
    OutputAnalyzer output = new OutputAnalyzer(pb.start());
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    67
    output.shouldContain("Initial young gen size set larger than the maximum young gen size");
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    68
  }
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    69
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    70
  private static boolean isRunningG1(String[] args) {
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    71
    for (int i = 0; i < args.length; i++) {
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    72
      if (args[i].contains("+UseG1GC")) {
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    73
        return true;
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    74
      }
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    75
    }
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    76
    return false;
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    77
  }
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    78
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    79
  private static String getMaxNewSize(String[] flags) throws Exception {
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    80
    ArrayList<String> finalargs = new ArrayList<String>();
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    81
    finalargs.addAll(Arrays.asList(flags));
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    82
    if (isRunningG1(flags)) {
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    83
      finalargs.add("-XX:G1HeapRegionSize=1M");
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    84
    }
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    85
    finalargs.add("-XX:+PrintFlagsFinal");
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    86
    finalargs.add("-version");
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    87
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    88
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(finalargs.toArray(new String[0]));
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    89
    OutputAnalyzer output = new OutputAnalyzer(pb.start());
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    90
    output.shouldHaveExitValue(0);
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    91
    String stdout = output.getStdout();
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    92
    //System.out.println(stdout);
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    93
    return getFlagValue("MaxNewSize", stdout);
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    94
  }
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    95
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    96
  private static String getFlagValue(String flag, String where) {
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    97
    Matcher m = Pattern.compile(flag + "\\s+:?=\\s+\\d+").matcher(where);
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    98
    if (!m.find()) {
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
    99
      throw new RuntimeException("Could not find value for flag " + flag + " in output string");
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
   100
    }
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
   101
    String match = m.group();
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
   102
    return match.substring(match.lastIndexOf(" ") + 1, match.length());
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
   103
  }
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
   104
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
   105
  public static void main(String args[]) throws Exception {
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
   106
    String gcName = args[0];
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
   107
    final int M32 = 32 * 1024 * 1024;
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
   108
    final int M64 = 64 * 1024 * 1024;
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
   109
    final int M96 = 96 * 1024 * 1024;
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
   110
    final int M128 = 128 * 1024 * 1024;
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
   111
    checkMaxNewSize(new String[] { gcName, "-Xmx128M" }, M128);
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
   112
    checkMaxNewSize(new String[] { gcName, "-Xmx128M", "-XX:NewRatio=5" }, M128);
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
   113
    checkMaxNewSize(new String[] { gcName, "-Xmx128M", "-XX:NewSize=32M" }, M128);
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
   114
    checkMaxNewSize(new String[] { gcName, "-Xmx128M", "-XX:OldSize=96M" }, M128);
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
   115
    checkMaxNewSize(new String[] { gcName, "-Xmx128M", "-XX:MaxNewSize=32M" }, M32);
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
   116
    checkMaxNewSize(new String[] { gcName, "-Xmx128M", "-XX:NewSize=32M", "-XX:MaxNewSize=32M" }, M32);
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
   117
    checkMaxNewSize(new String[] { gcName, "-Xmx128M", "-XX:NewRatio=6", "-XX:MaxNewSize=32M" }, M32);
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
   118
    checkMaxNewSize(new String[] { gcName, "-Xmx128M", "-Xms96M" }, M128);
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
   119
    checkMaxNewSize(new String[] { gcName, "-Xmx96M", "-Xms96M" }, M96);
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
   120
    checkMaxNewSize(new String[] { gcName, "-XX:NewSize=128M", "-XX:MaxNewSize=50M"}, M128);
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
   121
  }
c619b1cb4554 8016309: assert(eden_size > 0 && survivor_size > 0) failed: just checking
jwilhelm
parents:
diff changeset
   122
}