|
| 1 | +/* |
| 2 | + * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. |
| 3 | + * Copyright (C) 2025 THL A29 Limited, a Tencent company. All rights reserved. |
| 4 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 5 | + * |
| 6 | + * This code is free software; you can redistribute it and/or modify it |
| 7 | + * under the terms of the GNU General Public License version 2 only, as |
| 8 | + * published by the Free Software Foundation. |
| 9 | + * |
| 10 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 11 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 13 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 14 | + * accompanied this code). |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU General Public License version |
| 17 | + * 2 along with this work; if not, write to the Free Software Foundation, |
| 18 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | + * |
| 20 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 21 | + * or visit www.oracle.com if you need additional information or have any |
| 22 | + * questions. |
| 23 | + */ |
| 24 | + |
| 25 | +package gc.arguments; |
| 26 | + |
| 27 | +/* |
| 28 | + * @test TestG1CompressedOops |
| 29 | + * @bug 8354145 |
| 30 | + * @requires vm.gc.G1 & vm.opt.G1HeapRegionSize == null |
| 31 | + * @summary Verify that the flag TestG1CompressedOops is updated properly |
| 32 | + * @modules java.base/jdk.internal.misc |
| 33 | + * @modules java.management/sun.management |
| 34 | + * @library /test/lib |
| 35 | + * @library / |
| 36 | + * @run driver gc.arguments.TestG1CompressedOops |
| 37 | + */ |
| 38 | + |
| 39 | +import java.util.regex.Matcher; |
| 40 | +import java.util.regex.Pattern; |
| 41 | + |
| 42 | +import java.util.ArrayList; |
| 43 | +import java.util.Arrays; |
| 44 | + |
| 45 | +import jdk.test.lib.process.OutputAnalyzer; |
| 46 | + |
| 47 | +public class TestG1CompressedOops { |
| 48 | + |
| 49 | + private static void checkG1CompressedOops(String[] flags, boolean expectedValue, int exitValue) throws Exception { |
| 50 | + ArrayList<String> flagList = new ArrayList<String>(); |
| 51 | + flagList.addAll(Arrays.asList(flags)); |
| 52 | + flagList.add("-XX:+UseG1GC"); |
| 53 | + flagList.add("-XX:+PrintFlagsFinal"); |
| 54 | + flagList.add("-version"); |
| 55 | + |
| 56 | + OutputAnalyzer output = GCArguments.executeTestJava(flagList); |
| 57 | + output.shouldHaveExitValue(exitValue); |
| 58 | + |
| 59 | + if (exitValue == 0) { |
| 60 | + String stdout = output.getStdout(); |
| 61 | + boolean flagValue = getFlagValue("UseCompressedOops", stdout); |
| 62 | + if (flagValue != expectedValue) { |
| 63 | + throw new RuntimeException("Wrong value for UseCompressedOops. Expected " + expectedValue + " but got " + flagValue); |
| 64 | + } |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + private static boolean getFlagValue(String flag, String where) { |
| 69 | + Matcher m = Pattern.compile(flag + "\\s+:?=\\s+\\D+").matcher(where); |
| 70 | + if (!m.find()) { |
| 71 | + throw new RuntimeException("Could not find value for flag " + flag + " in output string"); |
| 72 | + } |
| 73 | + String match = m.group(); |
| 74 | + return match.contains("true"); |
| 75 | + } |
| 76 | + |
| 77 | + public static void main(String args[]) throws Exception { |
| 78 | + checkG1CompressedOops(new String[] { "-Xmx64m" /* default is 1m */ }, true, 0); |
| 79 | + checkG1CompressedOops(new String[] { "-Xmx64m", "-XX:G1HeapRegionSize=2m" }, true, 0); |
| 80 | + checkG1CompressedOops(new String[] { "-Xmx32768m" /* 32g will turn off the usecompressedoops */ }, false, 0); |
| 81 | + checkG1CompressedOops(new String[] { "-Xmx32760m" }, false, 0); |
| 82 | + checkG1CompressedOops(new String[] { "-Xmx32736m", /* 32g - 32m will turn on the usecomppressedoops */ }, true, 0); |
| 83 | + |
| 84 | + // if set G1HeapRegionSize explicitly with -Xmx32736m will turn off the UseCompressedOops |
| 85 | + checkG1CompressedOops(new String[] { "-Xmx32736m", "-XX:G1HeapRegionSize=1m" }, false, 0); |
| 86 | + checkG1CompressedOops(new String[] { "-Xmx32256m", "-XX:G1HeapRegionSize=512m" }, true, 0); |
| 87 | + } |
| 88 | +} |
0 commit comments