Skip to content

Commit 08d4afb

Browse files
Add InterpreterUtil.assertion
This helps avoid AssertionError in the interpreter.
1 parent addce59 commit 08d4afb

File tree

4 files changed

+23
-11
lines changed

4 files changed

+23
-11
lines changed

substratevm/src/com.oracle.svm.interpreter/src/com/oracle/svm/interpreter/Interpreter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ private static void initArguments(InterpreterFrame frame, InterpreterResolvedJav
322322
int receiverSlot = hasReceiver ? 1 : 0;
323323
int curSlot = 0;
324324
if (hasReceiver) {
325-
assert arguments[0] != null : "null receiver in init arguments !";
325+
InterpreterUtil.assertion(arguments[0] != null, "null receiver in init arguments !");
326326
Object receiver = arguments[0];
327327
setLocalObject(frame, curSlot, receiver);
328328
curSlot += JavaKind.Object.getSlotCount();

substratevm/src/com.oracle.svm.interpreter/src/com/oracle/svm/interpreter/InterpreterStubSection.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -278,35 +278,35 @@ private static Pointer enterHelper(InterpreterResolvedJavaMethod interpreterMeth
278278

279279
switch (returnType.getJavaKind()) {
280280
case Boolean:
281-
assert retVal instanceof Boolean;
281+
InterpreterUtil.assertion(retVal instanceof Boolean, "invalid return type");
282282
accessHelper.setGpReturn(enterData, ((Boolean) retVal) ? 1 : 0);
283283
break;
284284
case Byte:
285-
assert retVal instanceof Byte;
285+
InterpreterUtil.assertion(retVal instanceof Byte, "invalid return type");
286286
accessHelper.setGpReturn(enterData, ((Byte) retVal).longValue());
287287
break;
288288
case Short:
289-
assert retVal instanceof Short;
289+
InterpreterUtil.assertion(retVal instanceof Short, "invalid return type");
290290
accessHelper.setGpReturn(enterData, ((Short) retVal).longValue());
291291
break;
292292
case Char:
293-
assert retVal instanceof Character;
293+
InterpreterUtil.assertion(retVal instanceof Character, "invalid return type");
294294
accessHelper.setGpReturn(enterData, ((Character) retVal).charValue());
295295
break;
296296
case Int:
297-
assert retVal instanceof Integer;
297+
InterpreterUtil.assertion(retVal instanceof Integer, "invalid return type");
298298
accessHelper.setGpReturn(enterData, ((Integer) retVal).longValue());
299299
break;
300300
case Long:
301-
assert retVal instanceof Long;
301+
InterpreterUtil.assertion(retVal instanceof Long, "invalid return type");
302302
accessHelper.setGpReturn(enterData, (Long) retVal);
303303
break;
304304
case Float:
305-
assert retVal instanceof Float;
305+
InterpreterUtil.assertion(retVal instanceof Float, "invalid return type");
306306
accessHelper.setFpReturn(enterData, Float.floatToRawIntBits((float) retVal));
307307
break;
308308
case Double:
309-
assert retVal instanceof Double;
309+
InterpreterUtil.assertion(retVal instanceof Double, "invalid return type");
310310
accessHelper.setFpReturn(enterData, Double.doubleToRawLongBits((double) retVal));
311311
break;
312312
case Object:

substratevm/src/com.oracle.svm.interpreter/src/com/oracle/svm/interpreter/InterpreterUtil.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,20 @@
2424
*/
2525
package com.oracle.svm.interpreter;
2626

27-
import com.oracle.svm.core.log.Log;
2827
import org.graalvm.nativeimage.Platform;
2928
import org.graalvm.nativeimage.Platforms;
3029

30+
import com.oracle.svm.core.log.Log;
3131
import com.oracle.svm.core.util.VMError;
3232
import com.oracle.svm.interpreter.metadata.MetadataUtil;
3333

3434
public class InterpreterUtil {
35+
private static final boolean assertionsEnabled;
36+
static {
37+
boolean status = false;
38+
assert (status = true) == true;
39+
assertionsEnabled = status;
40+
}
3541

3642
/**
3743
* Alternative to {@link VMError#guarantee(boolean, String, Object)} that avoids
@@ -43,6 +49,12 @@ public static void guarantee(boolean condition, String simpleFormat, Object arg1
4349
}
4450
}
4551

52+
public static void assertion(boolean condition, String message) {
53+
if (assertionsEnabled && !condition) {
54+
VMError.guarantee(condition, message);
55+
}
56+
}
57+
4658
/**
4759
* Build time logging.
4860
*/

substratevm/src/com.oracle.svm.interpreter/src/com/oracle/svm/interpreter/SemanticJavaException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public Throwable fillInStackTrace() {
4646
}
4747

4848
public static RuntimeException raise(Throwable cause) {
49-
assert cause != null && !(cause instanceof SemanticJavaException);
49+
InterpreterUtil.assertion(cause != null && !(cause instanceof SemanticJavaException), "bad SemanticJavaException nesting");
5050
throw new SemanticJavaException(cause);
5151
}
5252
}

0 commit comments

Comments
 (0)