test/gc/arguments/TestMaxNewSize.java

Thu, 20 Mar 2014 16:31:47 +0100

author
jwilhelm
date
Thu, 20 Mar 2014 16:31:47 +0100
changeset 6400
3b4e1b5c13a0
parent 0
f90c822e73f8
permissions
-rw-r--r--

8037510: CMM Testing: Min/MaxHeapFreeRatio flags should be manageable through the API
Summary: Added tests for Min/MaxHeapFreeRatio flags
Reviewed-by: jwilhelm, tschatzl
Contributed-by: andrey.x.zakharov@oracle.com

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

mercurial