Skip to content

Commit 526951d

Browse files
tbzhangalbertnetymk
authored andcommitted
8354145: G1: UseCompressedOops boundary is calculated on maximum heap region size instead of maxiumum ergonomic heap region size
Reviewed-by: tschatzl, ayang
1 parent 765cef4 commit 526951d

File tree

4 files changed

+94
-0
lines changed

4 files changed

+94
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 4 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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.flagless
31+
* @summary Verify that the flag UseCompressedOops is updated properly
32+
* @library /test/lib
33+
* @library /
34+
* @run driver gc.arguments.TestG1CompressedOops
35+
*/
36+
37+
import java.util.regex.Matcher;
38+
import java.util.regex.Pattern;
39+
40+
import java.util.ArrayList;
41+
import java.util.Arrays;
42+
43+
import jdk.test.lib.process.OutputAnalyzer;
44+
45+
public class TestG1CompressedOops {
46+
47+
private static void checkG1CompressedOops(String[] flags, boolean expectedValue, int exitValue) throws Exception {
48+
ArrayList<String> flagList = new ArrayList<String>();
49+
flagList.addAll(Arrays.asList(flags));
50+
flagList.add("-XX:+UseG1GC");
51+
flagList.add("-XX:+PrintFlagsFinal");
52+
flagList.add("-version");
53+
54+
OutputAnalyzer output = GCArguments.executeTestJava(flagList);
55+
output.shouldHaveExitValue(exitValue);
56+
57+
if (exitValue == 0) {
58+
String stdout = output.getStdout();
59+
boolean flagValue = getFlagValue("UseCompressedOops", stdout);
60+
if (flagValue != expectedValue) {
61+
throw new RuntimeException("Wrong value for UseCompressedOops. Expected " + expectedValue + " but got " + flagValue);
62+
}
63+
}
64+
}
65+
66+
private static boolean getFlagValue(String flag, String where) {
67+
Matcher m = Pattern.compile(flag + "\\s+:?=\\s+\\D+").matcher(where);
68+
if (!m.find()) {
69+
throw new RuntimeException("Could not find value for flag " + flag + " in output string");
70+
}
71+
String match = m.group();
72+
return match.contains("true");
73+
}
74+
75+
public static void main(String args[]) throws Exception {
76+
checkG1CompressedOops(new String[] { "-Xmx64m" /* default is 1m */ }, true, 0);
77+
checkG1CompressedOops(new String[] { "-Xmx64m", "-XX:G1HeapRegionSize=2m" }, true, 0);
78+
checkG1CompressedOops(new String[] { "-Xmx32768m" /* 32g will turn off the usecompressedoops */ }, false, 0);
79+
checkG1CompressedOops(new String[] { "-Xmx32760m" }, false, 0);
80+
checkG1CompressedOops(new String[] { "-Xmx32736m", /* 32g - 32m will turn on the usecomppressedoops */ }, true, 0);
81+
82+
// if set G1HeapRegionSize explicitly with -Xmx32736m will turn off the UseCompressedOops
83+
checkG1CompressedOops(new String[] { "-Xmx32736m", "-XX:G1HeapRegionSize=1m" }, false, 0);
84+
checkG1CompressedOops(new String[] { "-Xmx32256m", "-XX:G1HeapRegionSize=512m" }, true, 0);
85+
}
86+
}

0 commit comments

Comments
 (0)