Skip to content

Commit 263e32b

Browse files
committed
8358694: VM asserts if CodeCacheSegmentSize is not a power of 2
Reviewed-by: shade, dfenacci
1 parent 7d6c902 commit 263e32b

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

src/hotspot/share/runtime/flags/jvmFlagConstraintsCompiler.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,13 @@ JVMFlag::Error OnStackReplacePercentageConstraintFunc(intx value, bool verbose)
156156
}
157157

158158
JVMFlag::Error CodeCacheSegmentSizeConstraintFunc(size_t value, bool verbose) {
159+
if (!is_power_of_2(value)) {
160+
JVMFlag::printError(verbose,
161+
"CodeCacheSegmentSize (%zu) must be "
162+
"a power of two\n", CodeCacheSegmentSize);
163+
return JVMFlag::VIOLATES_CONSTRAINT;
164+
}
165+
159166
if (CodeCacheSegmentSize < (size_t)CodeEntryAlignment) {
160167
JVMFlag::printError(verbose,
161168
"CodeCacheSegmentSize (%zu) must be "
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright (c) 2025 IBM Corporation. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
/*
25+
* @test
26+
* @bug 8358694
27+
* @summary Verifies that CodeCacheSegmentSize enforces power-of-two constraint:
28+
* - fails gracefully for invalid value
29+
* - succeeds for valid value
30+
* @library /test/lib
31+
* @run driver CodeCacheSegmentSizeTest
32+
*/
33+
34+
import jdk.test.lib.Platform;
35+
import jdk.test.lib.process.ProcessTools;
36+
import jdk.test.lib.process.OutputAnalyzer;
37+
38+
public class CodeCacheSegmentSizeTest {
39+
public static void main(String[] args) throws Exception {
40+
testInvalidValue();
41+
testValidValue();
42+
}
43+
44+
private static void testInvalidValue() throws Exception {
45+
ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(
46+
"-XX:+UnlockExperimentalVMOptions",
47+
"-XX:CodeCacheSegmentSize=65", // invalid value (not power of two)
48+
"-version"
49+
);
50+
51+
OutputAnalyzer output = new OutputAnalyzer(pb.start());
52+
53+
// Ensure no crash (no assert failure)
54+
output.shouldNotContain("assert");
55+
56+
// Expected graceful error output
57+
output.shouldContain("CodeCacheSegmentSize (65) must be a power of two");
58+
output.shouldContain("Error: Could not create the Java Virtual Machine.");
59+
output.shouldContain("Error: A fatal exception has occurred. Program will exit.");
60+
61+
// Graceful exit with error code 1
62+
output.shouldHaveExitValue(1);
63+
}
64+
65+
private static void testValidValue() throws Exception {
66+
ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(
67+
"-XX:+UnlockExperimentalVMOptions",
68+
"-XX:CodeCacheSegmentSize=64", // a valid power of 2
69+
"-version"
70+
);
71+
72+
OutputAnalyzer output = new OutputAnalyzer(pb.start());
73+
74+
output.shouldHaveExitValue(0);
75+
}
76+
}
77+

0 commit comments

Comments
 (0)