Skip to content

Commit eec397f

Browse files
Add better error message if the heap size exceeds the max. address space size.
1 parent 3944182 commit eec397f

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/HeapSizeVerifier.java

+18-9
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ private static void verifyMinHeapSize() {
7373

7474
UnsignedWord maxHeapSize = Word.unsigned(SubstrateGCOptions.MaxHeapSize.getValue());
7575
if (maxHeapSize.notEqual(0) && minHeapSize.aboveThan(maxHeapSize)) {
76-
throwError(minHeapSize, MIN_HEAP_SIZE_NAME, maxHeapSize, MAX_HEAP_SIZE_NAME);
76+
String message = formatError(minHeapSize, MIN_HEAP_SIZE_NAME, maxHeapSize, MAX_HEAP_SIZE_NAME);
77+
throw reportError(message);
7778
}
7879
}
7980

@@ -84,7 +85,8 @@ private static void verifyMaxNewSize() {
8485

8586
UnsignedWord maxHeapSize = Word.unsigned(SubstrateGCOptions.MaxHeapSize.getValue());
8687
if (maxHeapSize.notEqual(0) && maxNewSize.aboveThan(maxHeapSize)) {
87-
throwError(maxNewSize, MAX_NEW_SIZE_NAME, maxHeapSize, MAX_HEAP_SIZE_NAME);
88+
String message = formatError(maxNewSize, MAX_NEW_SIZE_NAME, maxHeapSize, MAX_HEAP_SIZE_NAME);
89+
throw reportError(message);
8890
}
8991
}
9092

@@ -103,24 +105,31 @@ public static void verifyMaxNewSizeAgainstMaxAddressSpaceSize(UnsignedWord maxNe
103105
private static void verifyAgainstMaxAddressSpaceSize(UnsignedWord actualValue, String actualValueName) {
104106
UnsignedWord maxAddressSpaceSize = ReferenceAccess.singleton().getMaxAddressSpaceSize();
105107
if (actualValue.aboveThan(maxAddressSpaceSize)) {
106-
throwError(actualValue, actualValueName, maxAddressSpaceSize, "largest possible heap address space");
108+
String message = formatError(actualValue, actualValueName, maxAddressSpaceSize, "largest possible heap address space");
109+
if (ReferenceAccess.singleton().getCompressionShift() > 0) {
110+
message += " To allow larger values, please disable compressed references when building the image by adding the option '-H:-UseCompressedReferences'";
111+
}
112+
throw reportError(message);
107113
}
108114
}
109115

110116
private static void verifyAgainstReservedAddressSpaceSize(UnsignedWord actualValue, String actualValueName) {
111117
UnsignedWord reservedAddressSpaceSize = Word.unsigned(SubstrateGCOptions.ReservedAddressSpaceSize.getValue());
112118
if (reservedAddressSpaceSize.notEqual(0) && actualValue.aboveThan(reservedAddressSpaceSize)) {
113-
throwError(actualValue, actualValueName, reservedAddressSpaceSize, "value of the option '" + SubstrateGCOptions.ReservedAddressSpaceSize.getName() + "'");
119+
String message = formatError(actualValue, actualValueName, reservedAddressSpaceSize, SubstrateGCOptions.ReservedAddressSpaceSize.getName());
120+
throw reportError(message);
114121
}
115122
}
116123

117-
private static void throwError(UnsignedWord actualValue, String actualValueName, UnsignedWord maxValue, String maxValueName) throws UserException {
124+
private static RuntimeException reportError(String message) throws UserException {
118125
if (SubstrateUtil.HOSTED) {
119-
throw UserError.abort("The specified %s (%s) must not be larger than the %s (%s).", actualValueName, format(actualValue), maxValueName, format(maxValue));
120-
} else {
121-
throw new IllegalArgumentException(
122-
"The specified " + actualValueName + " (" + format(actualValue) + ") must not be larger than the " + maxValueName + " (" + format(maxValue) + ").");
126+
throw UserError.abort(message);
123127
}
128+
throw new IllegalArgumentException(message);
129+
}
130+
131+
private static String formatError(UnsignedWord actualValue, String actualValueName, UnsignedWord maxValue, String maxValueName) {
132+
return "The specified " + actualValueName + " (" + format(actualValue) + ") must not be larger than the " + maxValueName + " (" + format(maxValue) + ").";
124133
}
125134

126135
private static String format(UnsignedWord bytes) {

0 commit comments

Comments
 (0)