Skip to content

Commit c31c734

Browse files
committed
G1GC: keep the CompressedOops same as before when not setting HeapRegionSize explicitly
1 parent cd9fa3f commit c31c734

File tree

4 files changed

+96
-0
lines changed

4 files changed

+96
-0
lines changed

src/hotspot/share/gc/g1/g1Arguments.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ void G1Arguments::initialize_alignments() {
7171
}
7272

7373
size_t G1Arguments::conservative_max_heap_alignment() {
74+
if (FLAG_IS_DEFAULT(G1HeapRegionSize)) {
75+
return G1HeapRegion::max_ergonomics_size();
76+
}
7477
return G1HeapRegion::max_region_size();
7578
}
7679

src/hotspot/share/gc/g1/g1HeapRegion.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ size_t G1HeapRegion::max_region_size() {
5757
return G1HeapRegionBounds::max_size();
5858
}
5959

60+
size_t G1HeapRegion::max_ergonomics_size() {
61+
return G1HeapRegionBounds::max_ergonomics_size();
62+
}
63+
6064
size_t G1HeapRegion::min_region_size_in_words() {
6165
return G1HeapRegionBounds::min_size() >> LogHeapWordSize;
6266
}

src/hotspot/share/gc/g1/g1HeapRegion.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ class G1HeapRegion : public CHeapObj<mtGC> {
316316
}
317317

318318
static size_t max_region_size();
319+
static size_t max_ergonomics_size();
319320
static size_t min_region_size_in_words();
320321

321322
// It sets up the heap region size (GrainBytes / GrainWords), as well as
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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

Comments
 (0)