Skip to content

Commit 577babf

Browse files
author
Thomas Schatzl
committed
8334010: VM crashes with ObjectAlignmentInBytes > GCCardSizeInBytes
Reviewed-by: shade, iwalulya
1 parent b9b0bd0 commit 577babf

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

src/hotspot/share/gc/shared/gcArguments.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "runtime/arguments.hpp"
3131
#include "runtime/globals.hpp"
3232
#include "runtime/globals_extension.hpp"
33+
#include "utilities/formatBuffer.hpp"
3334
#include "utilities/macros.hpp"
3435

3536
size_t HeapAlignment = 0;
@@ -166,6 +167,13 @@ void GCArguments::initialize_heap_flags_and_sizes() {
166167

167168
FLAG_SET_ERGO(MinHeapDeltaBytes, align_up(MinHeapDeltaBytes, SpaceAlignment));
168169

170+
if (checked_cast<uint>(ObjectAlignmentInBytes) > GCCardSizeInBytes) {
171+
err_msg message("ObjectAlignmentInBytes %u is larger than GCCardSizeInBytes %u",
172+
ObjectAlignmentInBytes, GCCardSizeInBytes);
173+
vm_exit_during_initialization("Invalid combination of GCCardSizeInBytes and ObjectAlignmentInBytes",
174+
message);
175+
}
176+
169177
DEBUG_ONLY(assert_flags();)
170178
}
171179

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright (c) 2024, Oracle and/or its affiliates. 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+
package gc;
25+
26+
/* @test TestObjectAlignmentCardSize.java
27+
* @summary Test to check correct handling of ObjectAlignmentInBytes and GCCardSizeInBytes combinations
28+
* @requires vm.gc != "Z"
29+
* @library /test/lib
30+
* @modules java.base/jdk.internal.misc
31+
* @run driver gc.TestObjectAlignmentCardSize
32+
*/
33+
34+
import jdk.test.lib.process.ProcessTools;
35+
import jdk.test.lib.process.OutputAnalyzer;
36+
37+
public class TestObjectAlignmentCardSize {
38+
private static void runTest(int objectAlignment, int cardSize, boolean shouldSucceed) throws Exception {
39+
OutputAnalyzer output = ProcessTools.executeTestJava(
40+
"-XX:ObjectAlignmentInBytes=" + objectAlignment,
41+
"-XX:GCCardSizeInBytes=" + cardSize,
42+
"-Xmx32m",
43+
"-Xms32m",
44+
"-version");
45+
46+
System.out.println("Output:\n" + output.getOutput());
47+
48+
if (shouldSucceed) {
49+
output.shouldHaveExitValue(0);
50+
} else {
51+
output.shouldContain("Invalid combination of GCCardSizeInBytes and ObjectAlignmentInBytes");
52+
output.shouldNotHaveExitValue(0);
53+
}
54+
}
55+
56+
public static void main(String[] args) throws Exception {
57+
runTest(8, 512, true);
58+
runTest(128, 128, true);
59+
runTest(256, 128, false);
60+
runTest(256, 256, true);
61+
runTest(256, 512, true);
62+
}
63+
}

0 commit comments

Comments
 (0)