Path: blob/master/test/hotspot/jtreg/gc/arguments/TestG1HeapRegionSize.java
40942 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 TestG1HeapRegionSize27* @bug 802187928* @requires vm.gc.G129* @summary Verify that the flag G1HeapRegionSize is updated properly30* @modules java.base/jdk.internal.misc31* @modules java.management/sun.management32* @library /test/lib33* @library /34* @run driver gc.arguments.TestG1HeapRegionSize35*/3637import java.util.regex.Matcher;38import java.util.regex.Pattern;3940import java.util.ArrayList;41import java.util.Arrays;4243import jdk.test.lib.process.OutputAnalyzer;44import jdk.test.lib.process.ProcessTools;4546public class TestG1HeapRegionSize {4748private static void checkG1HeapRegionSize(String[] flags, int expectedValue, int exitValue) throws Exception {49ArrayList<String> flagList = new ArrayList<String>();50flagList.addAll(Arrays.asList(flags));51flagList.add("-XX:+UseG1GC");52flagList.add("-XX:+PrintFlagsFinal");53flagList.add("-version");5455ProcessBuilder pb = GCArguments.createJavaProcessBuilder(flagList);56OutputAnalyzer output = new OutputAnalyzer(pb.start());57output.shouldHaveExitValue(exitValue);5859if (exitValue == 0) {60String stdout = output.getStdout();61int flagValue = getFlagValue("G1HeapRegionSize", stdout);62if (flagValue != expectedValue) {63throw new RuntimeException("Wrong value for G1HeapRegionSize. Expected " + expectedValue + " but got " + flagValue);64}65}66}6768private static int getFlagValue(String flag, String where) {69Matcher m = Pattern.compile(flag + "\\s+:?=\\s+\\d+").matcher(where);70if (!m.find()) {71throw new RuntimeException("Could not find value for flag " + flag + " in output string");72}73String match = m.group();74return Integer.parseInt(match.substring(match.lastIndexOf(" ") + 1, match.length()));75}7677public static void main(String args[]) throws Exception {78final int M = 1024 * 1024;7980checkG1HeapRegionSize(new String[] { "-Xmx64m" /* default is 1m */ }, 1*M, 0);81checkG1HeapRegionSize(new String[] { "-Xmx64m", "-XX:G1HeapRegionSize=2m" }, 2*M, 0);82checkG1HeapRegionSize(new String[] { "-Xmx64m", "-XX:G1HeapRegionSize=3m" }, 4*M, 0);83checkG1HeapRegionSize(new String[] { "-Xmx256m", "-XX:G1HeapRegionSize=32m" }, 32*M, 0);84checkG1HeapRegionSize(new String[] { "-Xmx256m", "-XX:G1HeapRegionSize=64m" }, 32*M, 1);85}86}878889