Path: blob/master/test/hotspot/jtreg/gc/arguments/TestMaxNewSize.java
40943 views
/*1* Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package gc.arguments;2425/*26* @test TestMaxNewSizeSerial27* @bug 705793928* @summary Make sure that MaxNewSize always has a useful value after argument29* processing.30* @requires vm.gc.Serial31* @library /test/lib32* @library /33* @modules java.base/jdk.internal.misc34* java.management35* @run driver gc.arguments.TestMaxNewSize -XX:+UseSerialGC36* @author [email protected], [email protected]37*/3839/*40* @test TestMaxNewSizeParallel41* @bug 705793942* @summary Make sure that MaxNewSize always has a useful value after argument43* processing.44* @requires vm.gc.Parallel45* @library /test/lib46* @library /47* @modules java.base/jdk.internal.misc48* java.management49* @run driver gc.arguments.TestMaxNewSize -XX:+UseParallelGC50* @author [email protected], [email protected]51*/5253/*54* @test TestMaxNewSizeG155* @bug 705793956* @summary Make sure that MaxNewSize always has a useful value after argument57* processing.58* @requires vm.gc.G159* @library /test/lib60* @library /61* @modules java.base/jdk.internal.misc62* java.management63* @run driver gc.arguments.TestMaxNewSize -XX:+UseG1GC64* @author [email protected], [email protected]65*/6667import java.util.regex.Matcher;68import java.util.regex.Pattern;6970import java.math.BigInteger;7172import java.util.ArrayList;73import java.util.Arrays;7475import jdk.test.lib.process.OutputAnalyzer;76import jdk.test.lib.process.ProcessTools;7778public class TestMaxNewSize {7980private static void checkMaxNewSize(String[] flags, int heapsize) throws Exception {81BigInteger actual = new BigInteger(getMaxNewSize(flags));82System.out.println(actual);83if (actual.compareTo(new BigInteger((new Long(heapsize)).toString())) == 1) {84throw new RuntimeException("MaxNewSize value set to \"" + actual +85"\", expected otherwise when running with the following flags: " + Arrays.asList(flags).toString());86}87}8889private static void checkIncompatibleNewSize(String[] flags) throws Exception {90ArrayList<String> finalargs = new ArrayList<String>();91finalargs.addAll(Arrays.asList(flags));92finalargs.add("-version");9394ProcessBuilder pb = GCArguments.createJavaProcessBuilder(finalargs);95OutputAnalyzer output = new OutputAnalyzer(pb.start());96output.shouldContain("Initial young gen size set larger than the maximum young gen size");97}9899private static boolean isRunningG1(String[] args) {100for (int i = 0; i < args.length; i++) {101if (args[i].contains("+UseG1GC")) {102return true;103}104}105return false;106}107108private static String getMaxNewSize(String[] flags) throws Exception {109ArrayList<String> finalargs = new ArrayList<String>();110finalargs.addAll(Arrays.asList(flags));111if (isRunningG1(flags)) {112finalargs.add("-XX:G1HeapRegionSize=1M");113}114finalargs.add("-XX:+PrintFlagsFinal");115finalargs.add("-version");116117ProcessBuilder pb = GCArguments.createJavaProcessBuilder(finalargs);118OutputAnalyzer output = new OutputAnalyzer(pb.start());119output.shouldHaveExitValue(0);120String stdout = output.getStdout();121//System.out.println(stdout);122return getFlagValue("MaxNewSize", stdout);123}124125private static String getFlagValue(String flag, String where) {126Matcher m = Pattern.compile(flag + "\\s+:?=\\s+\\d+").matcher(where);127if (!m.find()) {128throw new RuntimeException("Could not find value for flag " + flag + " in output string");129}130String match = m.group();131return match.substring(match.lastIndexOf(" ") + 1, match.length());132}133134public static void main(String args[]) throws Exception {135String gcName = args[0];136final int M = 1024 * 1024;137checkMaxNewSize(new String[] { gcName, "-Xmx128M" }, 128 * M);138checkMaxNewSize(new String[] { gcName, "-Xmx128M", "-XX:NewRatio=5" }, 128 * M);139checkMaxNewSize(new String[] { gcName, "-Xmx128M", "-XX:NewSize=32M" }, 128 * M);140checkMaxNewSize(new String[] { gcName, "-Xmx128M", "-XX:OldSize=96M" }, 128 * M);141checkMaxNewSize(new String[] { gcName, "-Xmx128M", "-XX:MaxNewSize=32M" }, 32 * M);142checkMaxNewSize(new String[] { gcName, "-Xmx128M", "-XX:NewSize=32M", "-XX:MaxNewSize=32M" }, 32 * M);143checkMaxNewSize(new String[] { gcName, "-Xmx128M", "-XX:NewRatio=6", "-XX:MaxNewSize=32M" }, 32 * M);144checkMaxNewSize(new String[] { gcName, "-Xmx128M", "-Xms96M" }, 128 * M);145checkMaxNewSize(new String[] { gcName, "-Xmx96M", "-Xms96M" }, 96 * M);146checkMaxNewSize(new String[] { gcName, "-XX:NewSize=128M", "-XX:MaxNewSize=50M"}, 128 * M);147}148}149150151