Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/gc/arguments/TestMaxNewSize.java
32285 views
/*1* Copyright (c) 2013, 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*/2223/*24* @test TestMaxNewSize25* @key gc26* @bug 705793927* @summary Make sure that MaxNewSize always has a useful value after argument28* processing.29* @library /testlibrary30* @build TestMaxNewSize31* @run main TestMaxNewSize -XX:+UseSerialGC32* @run main TestMaxNewSize -XX:+UseParallelGC33* @run main TestMaxNewSize -XX:+UseConcMarkSweepGC34* @run main TestMaxNewSize -XX:+UseG1GC35* @author [email protected], [email protected]36*/3738import java.util.regex.Matcher;39import java.util.regex.Pattern;4041import java.math.BigInteger;4243import java.util.ArrayList;44import java.util.Arrays;4546import com.oracle.java.testlibrary.*;4748public class TestMaxNewSize {4950private static void checkMaxNewSize(String[] flags, int heapsize) throws Exception {51BigInteger actual = new BigInteger(getMaxNewSize(flags));52System.out.println(actual);53if (actual.compareTo(new BigInteger((new Long(heapsize)).toString())) == 1) {54throw new RuntimeException("MaxNewSize value set to \"" + actual +55"\", expected otherwise when running with the following flags: " + Arrays.asList(flags).toString());56}57}5859private static void checkIncompatibleNewSize(String[] flags) throws Exception {60ArrayList<String> finalargs = new ArrayList<String>();61finalargs.addAll(Arrays.asList(flags));62finalargs.add("-version");6364ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(finalargs.toArray(new String[0]));65OutputAnalyzer output = new OutputAnalyzer(pb.start());66output.shouldContain("Initial young gen size set larger than the maximum young gen size");67}6869private static boolean isRunningG1(String[] args) {70for (int i = 0; i < args.length; i++) {71if (args[i].contains("+UseG1GC")) {72return true;73}74}75return false;76}7778private static String getMaxNewSize(String[] flags) throws Exception {79ArrayList<String> finalargs = new ArrayList<String>();80finalargs.addAll(Arrays.asList(flags));81if (isRunningG1(flags)) {82finalargs.add("-XX:G1HeapRegionSize=1M");83}84finalargs.add("-XX:+PrintFlagsFinal");85finalargs.add("-version");8687ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(finalargs.toArray(new String[0]));88OutputAnalyzer output = new OutputAnalyzer(pb.start());89output.shouldHaveExitValue(0);90String stdout = output.getStdout();91//System.out.println(stdout);92return getFlagValue("MaxNewSize", stdout);93}9495private static String getFlagValue(String flag, String where) {96Matcher m = Pattern.compile(flag + "\\s+:?=\\s+\\d+").matcher(where);97if (!m.find()) {98throw new RuntimeException("Could not find value for flag " + flag + " in output string");99}100String match = m.group();101return match.substring(match.lastIndexOf(" ") + 1, match.length());102}103104public static void main(String args[]) throws Exception {105String gcName = args[0];106final int M32 = 32 * 1024 * 1024;107final int M64 = 64 * 1024 * 1024;108final int M96 = 96 * 1024 * 1024;109final int M128 = 128 * 1024 * 1024;110checkMaxNewSize(new String[] { gcName, "-Xmx128M" }, M128);111checkMaxNewSize(new String[] { gcName, "-Xmx128M", "-XX:NewRatio=5" }, M128);112checkMaxNewSize(new String[] { gcName, "-Xmx128M", "-XX:NewSize=32M" }, M128);113checkMaxNewSize(new String[] { gcName, "-Xmx128M", "-XX:OldSize=96M" }, M128);114checkMaxNewSize(new String[] { gcName, "-Xmx128M", "-XX:MaxNewSize=32M" }, M32);115checkMaxNewSize(new String[] { gcName, "-Xmx128M", "-XX:NewSize=32M", "-XX:MaxNewSize=32M" }, M32);116checkMaxNewSize(new String[] { gcName, "-Xmx128M", "-XX:NewRatio=6", "-XX:MaxNewSize=32M" }, M32);117checkMaxNewSize(new String[] { gcName, "-Xmx128M", "-Xms96M" }, M128);118checkMaxNewSize(new String[] { gcName, "-Xmx96M", "-Xms96M" }, M96);119checkMaxNewSize(new String[] { gcName, "-XX:NewSize=128M", "-XX:MaxNewSize=50M"}, M128);120}121}122123124