Skip to content

Commit b101586

Browse files
committed
8332514: Allow class space size to be larger than 3GB
Reviewed-by: iklam, dholmes
1 parent 5ed0d52 commit b101586

File tree

3 files changed

+132
-52
lines changed

3 files changed

+132
-52
lines changed

src/hotspot/share/cds/metaspaceShared.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1303,7 +1303,7 @@ char* MetaspaceShared::reserve_address_space_for_archives(FileMapInfo* static_ma
13031303
"Archive base address unaligned: " PTR_FORMAT ", needs alignment: %zu.",
13041304
p2i(base_address), base_address_alignment);
13051305

1306-
const size_t class_space_size = CompressedClassSpaceSize;
1306+
size_t class_space_size = CompressedClassSpaceSize;
13071307
assert(CompressedClassSpaceSize > 0 &&
13081308
is_aligned(CompressedClassSpaceSize, class_space_alignment),
13091309
"CompressedClassSpaceSize malformed: "
@@ -1312,6 +1312,16 @@ char* MetaspaceShared::reserve_address_space_for_archives(FileMapInfo* static_ma
13121312
const size_t ccs_begin_offset = align_up(archive_space_size, class_space_alignment);
13131313
const size_t gap_size = ccs_begin_offset - archive_space_size;
13141314

1315+
// Reduce class space size if it would not fit into the Klass encoding range
1316+
constexpr size_t max_encoding_range_size = 4 * G;
1317+
guarantee(archive_space_size < max_encoding_range_size - class_space_alignment, "Archive too large");
1318+
if ((archive_space_size + gap_size + class_space_size) > max_encoding_range_size) {
1319+
class_space_size = align_down(max_encoding_range_size - archive_space_size - gap_size, class_space_alignment);
1320+
log_info(metaspace)("CDS initialization: reducing class space size from " SIZE_FORMAT " to " SIZE_FORMAT,
1321+
CompressedClassSpaceSize, class_space_size);
1322+
FLAG_SET_ERGO(CompressedClassSpaceSize, class_space_size);
1323+
}
1324+
13151325
const size_t total_range_size =
13161326
archive_space_size + gap_size + class_space_size;
13171327

src/hotspot/share/runtime/globals.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1399,7 +1399,7 @@ const int ObjectAlignmentInBytes = 8;
13991399
product(size_t, CompressedClassSpaceSize, 1*G, \
14001400
"Maximum size of class area in Metaspace when compressed " \
14011401
"class pointers are used") \
1402-
range(1*M, 3*G) \
1402+
range(1*M, LP64_ONLY(4*G) NOT_LP64(max_uintx)) \
14031403
\
14041404
develop(size_t, CompressedClassSpaceBaseAddress, 0, \
14051405
"Force the class space to be allocated at this address or " \

test/hotspot/jtreg/runtime/CompressedOops/CompressedClassSpaceSize.java

Lines changed: 120 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -22,75 +22,145 @@
2222
*/
2323

2424
/*
25-
* @test
25+
* @test id=invalid
2626
* @bug 8022865
2727
* @summary Tests for the -XX:CompressedClassSpaceSize command line option
2828
* @requires vm.bits == 64 & vm.opt.final.UseCompressedOops == true
2929
* @requires vm.flagless
3030
* @library /test/lib
31-
* @modules java.base/jdk.internal.misc
32-
* java.management
33-
* @run driver CompressedClassSpaceSize
31+
* @modules java.base/jdk.internal.misc java.management
32+
* @run driver CompressedClassSpaceSize invalid
33+
*/
34+
35+
/*
36+
* @test id=valid_small
37+
* @bug 8022865
38+
* @summary Tests for the -XX:CompressedClassSpaceSize command line option
39+
* @requires vm.bits == 64 & vm.opt.final.UseCompressedOops == true
40+
* @requires vm.flagless
41+
* @library /test/lib
42+
* @modules java.base/jdk.internal.misc java.management
43+
* @run driver CompressedClassSpaceSize valid_small
44+
*/
45+
46+
/*
47+
* @test id=valid_large_nocds
48+
* @bug 8022865
49+
* @summary Tests for the -XX:CompressedClassSpaceSize command line option
50+
* @requires vm.bits == 64 & vm.opt.final.UseCompressedOops == true
51+
* @requires vm.flagless
52+
* @library /test/lib
53+
* @modules java.base/jdk.internal.misc java.management
54+
* @run driver CompressedClassSpaceSize valid_large_nocds
55+
*/
56+
57+
/*
58+
* @test id=valid_large_cds
59+
* @bug 8022865
60+
* @summary Tests for the -XX:CompressedClassSpaceSize command line option
61+
* @requires vm.bits == 64 & vm.opt.final.UseCompressedOops == true & vm.cds
62+
* @requires vm.flagless
63+
* @library /test/lib
64+
* @modules java.base/jdk.internal.misc java.management
65+
* @run driver CompressedClassSpaceSize valid_large_cds
3466
*/
3567

3668
import jdk.test.lib.process.ProcessTools;
3769
import jdk.test.lib.process.OutputAnalyzer;
3870

3971
public class CompressedClassSpaceSize {
4072

41-
public static void main(String[] args) throws Exception {
42-
ProcessBuilder pb;
43-
OutputAnalyzer output;
44-
// Minimum size is 1MB
45-
pb = ProcessTools.createLimitedTestJavaProcessBuilder("-XX:CompressedClassSpaceSize=0",
46-
"-version");
47-
output = new OutputAnalyzer(pb.start());
48-
output.shouldContain("outside the allowed range")
49-
.shouldHaveExitValue(1);
50-
51-
// Invalid size of -1 should be handled correctly
52-
pb = ProcessTools.createLimitedTestJavaProcessBuilder("-XX:CompressedClassSpaceSize=-1",
53-
"-version");
54-
output = new OutputAnalyzer(pb.start());
55-
output.shouldContain("Improperly specified VM option 'CompressedClassSpaceSize=-1'")
56-
.shouldHaveExitValue(1);
73+
final static long MB = 1024 * 1024;
5774

75+
final static long minAllowedClassSpaceSize = MB;
76+
final static long minRealClassSpaceSize = 16 * MB;
77+
final static long maxClassSpaceSize = 4096 * MB;
5878

59-
// Maximum size is 3GB
60-
pb = ProcessTools.createLimitedTestJavaProcessBuilder("-XX:CompressedClassSpaceSize=4g",
61-
"-version");
62-
output = new OutputAnalyzer(pb.start());
63-
output.shouldContain("outside the allowed range")
64-
.shouldHaveExitValue(1);
79+
// For the valid_large_cds sub test: we need to have a notion of what archive size to
80+
// maximally expect, with a generous fudge factor to avoid having to tweak this test
81+
// ofent. Note: today's default archives are around 16-20 MB.
82+
final static long maxExpectedArchiveSize = 512 * MB;
6583

84+
public static void main(String[] args) throws Exception {
85+
ProcessBuilder pb;
86+
OutputAnalyzer output;
6687

67-
// Make sure the minimum size is set correctly and printed
68-
// (Note: ccs size are rounded up to the next larger root chunk boundary (16m).
69-
// Note that this is **reserved** size and does not affect rss.
70-
pb = ProcessTools.createLimitedTestJavaProcessBuilder("-XX:+UnlockDiagnosticVMOptions",
71-
"-XX:CompressedClassSpaceSize=1m",
72-
"-Xlog:gc+metaspace=trace",
73-
"-version");
74-
output = new OutputAnalyzer(pb.start());
75-
output.shouldMatch("Compressed class space.*16777216")
76-
.shouldHaveExitValue(0);
88+
switch (args[0]) {
89+
case "invalid": {
90+
// < Minimum size
91+
pb = ProcessTools.createLimitedTestJavaProcessBuilder("-XX:CompressedClassSpaceSize=0",
92+
"-version");
93+
output = new OutputAnalyzer(pb.start());
94+
output.shouldContain("outside the allowed range")
95+
.shouldHaveExitValue(1);
7796

97+
// Invalid size of -1 should be handled correctly
98+
pb = ProcessTools.createLimitedTestJavaProcessBuilder("-XX:CompressedClassSpaceSize=-1",
99+
"-version");
100+
output = new OutputAnalyzer(pb.start());
101+
output.shouldContain("Improperly specified VM option 'CompressedClassSpaceSize=-1'")
102+
.shouldHaveExitValue(1);
78103

79-
// Make sure the maximum size is set correctly and printed
80-
pb = ProcessTools.createLimitedTestJavaProcessBuilder("-XX:+UnlockDiagnosticVMOptions",
81-
"-XX:CompressedClassSpaceSize=3g",
82-
"-Xlog:gc+metaspace=trace",
83-
"-version");
84-
output = new OutputAnalyzer(pb.start());
85-
output.shouldMatch("Compressed class space.*3221225472")
86-
.shouldHaveExitValue(0);
104+
// > Maximum size
105+
pb = ProcessTools.createLimitedTestJavaProcessBuilder("-XX:CompressedClassSpaceSize=" + maxClassSpaceSize + 1,
106+
"-version");
107+
output = new OutputAnalyzer(pb.start());
108+
output.shouldContain("outside the allowed range")
109+
.shouldHaveExitValue(1);
87110

111+
pb = ProcessTools.createLimitedTestJavaProcessBuilder("-XX:-UseCompressedClassPointers",
112+
"-XX:CompressedClassSpaceSize=" + minAllowedClassSpaceSize,
113+
"-version");
114+
output = new OutputAnalyzer(pb.start());
115+
output.shouldContain("Setting CompressedClassSpaceSize has no effect when compressed class pointers are not used")
116+
.shouldHaveExitValue(0);
117+
}
118+
break;
119+
case "valid_small": {
120+
// Make sure the minimum size is set correctly and printed
121+
// (Note: ccs size are rounded up to the next larger root chunk boundary (16m).
122+
// Note that this is **reserved** size and does not affect rss.
123+
pb = ProcessTools.createLimitedTestJavaProcessBuilder("-XX:+UnlockDiagnosticVMOptions",
124+
"-XX:CompressedClassSpaceSize=" + minAllowedClassSpaceSize,
125+
"-Xlog:gc+metaspace",
126+
"-version");
127+
output = new OutputAnalyzer(pb.start());
128+
output.shouldMatch("Compressed class space.*" + minRealClassSpaceSize)
129+
.shouldHaveExitValue(0);
130+
}
131+
break;
132+
case "valid_large_nocds": {
133+
// Without CDS, we should get 4G
134+
pb = ProcessTools.createLimitedTestJavaProcessBuilder("-XX:CompressedClassSpaceSize=" + maxClassSpaceSize,
135+
"-Xshare:off", "-Xlog:metaspace*", "-version");
136+
output = new OutputAnalyzer(pb.start());
137+
output.shouldMatch("Compressed class space.*" + maxClassSpaceSize)
138+
.shouldHaveExitValue(0);
139+
}
140+
break;
141+
case "valid_large_cds": {
142+
// Create archive
143+
pb = ProcessTools.createLimitedTestJavaProcessBuilder(
144+
"-XX:SharedArchiveFile=./abc.jsa", "-Xshare:dump", "-version");
145+
output = new OutputAnalyzer(pb.start());
146+
output.shouldHaveExitValue(0);
88147

89-
pb = ProcessTools.createLimitedTestJavaProcessBuilder("-XX:-UseCompressedClassPointers",
90-
"-XX:CompressedClassSpaceSize=1m",
91-
"-version");
92-
output = new OutputAnalyzer(pb.start());
93-
output.shouldContain("Setting CompressedClassSpaceSize has no effect when compressed class pointers are not used")
94-
.shouldHaveExitValue(0);
148+
// With CDS, class space should fill whatever the CDS archive leaves us (modulo alignment)
149+
pb = ProcessTools.createLimitedTestJavaProcessBuilder("-XX:CompressedClassSpaceSize=" + maxClassSpaceSize,
150+
"-XX:SharedArchiveFile=./abc.jsa", "-Xshare:on", "-Xlog:metaspace*", "-version");
151+
output = new OutputAnalyzer(pb.start());
152+
output.shouldHaveExitValue(0);
153+
long reducedSize = Long.parseLong(
154+
output.firstMatch("reducing class space size from " + maxClassSpaceSize + " to (\\d+)", 1));
155+
if (reducedSize < (maxClassSpaceSize - maxExpectedArchiveSize)) {
156+
output.reportDiagnosticSummary();
157+
throw new RuntimeException("Class space size too small?");
158+
}
159+
output.shouldMatch("Compressed class space.*" + reducedSize);
160+
}
161+
break;
162+
default:
163+
throw new RuntimeException("invalid sub test " + args[0]);
164+
}
95165
}
96166
}

0 commit comments

Comments
 (0)