Skip to content

Commit c7894e3

Browse files
committed
Replace VMError guarantees with assertions.
1 parent 10612a2 commit c7894e3

File tree

6 files changed

+20
-29
lines changed

6 files changed

+20
-29
lines changed

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SVMHost.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public enum UsageKind {
221221
private final boolean buildingImageLayer = ImageLayerBuildingSupport.buildingImageLayer();
222222
private final LayeredStaticFieldSupport layeredStaticFieldSupport;
223223

224-
private final StrictDynamicAccessInferenceSupport dynamicAccessInferenceSupport;
224+
private final StrictDynamicAccessInferenceSupport strictDynamicAccessInferenceSupport;
225225

226226
@SuppressWarnings("this-escape")
227227
public SVMHost(OptionValues options, ImageClassLoader loader, ClassInitializationSupport classInitializationSupport, AnnotationSubstitutionProcessor annotationSubstitutions,
@@ -260,7 +260,7 @@ public SVMHost(OptionValues options, ImageClassLoader loader, ClassInitializatio
260260
enableReachableInCurrentLayer = ImageLayerBuildingSupport.buildingExtensionLayer();
261261
layeredStaticFieldSupport = ImageLayerBuildingSupport.buildingImageLayer() ? LayeredStaticFieldSupport.singleton() : null;
262262

263-
dynamicAccessInferenceSupport = StrictDynamicAccessInferenceFeature.isDisabled() ? null : StrictDynamicAccessInferenceSupport.singleton();
263+
strictDynamicAccessInferenceSupport = StrictDynamicAccessInferenceFeature.isDisabled() ? null : StrictDynamicAccessInferenceSupport.singleton();
264264
}
265265

266266
/**
@@ -1278,6 +1278,6 @@ public SimulateClassInitializerSupport createSimulateClassInitializerSupport(Ana
12781278
}
12791279

12801280
public StrictDynamicAccessInferenceSupport getStrictDynamicAccessInferenceSupport() {
1281-
return dynamicAccessInferenceSupport;
1281+
return strictDynamicAccessInferenceSupport;
12821282
}
12831283
}

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/dataflow/AbstractFrame.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
import java.util.function.Function;
3434
import java.util.function.Predicate;
3535

36-
import com.oracle.svm.core.util.VMError;
37-
3836
/**
3937
* Abstract representation of a bytecode execution frame, i.e., its
4038
* {@link AbstractFrame#operandStack operand stack} and {@link AbstractFrame#localVariableTable
@@ -173,12 +171,12 @@ void push(ValueWithSlots<T> value) {
173171
}
174172

175173
ValueWithSlots<T> pop() {
176-
VMError.guarantee(!stack.isEmpty(), "Cannot pop from empty stack");
174+
assert !stack.isEmpty() : "Cannot pop from empty stack";
177175
return stack.removeLast();
178176
}
179177

180178
ValueWithSlots<T> peek(int depth) {
181-
VMError.guarantee(0 <= depth && depth < size(), "Operand stack doesn't contain enough values");
179+
assert 0 <= depth && depth < size() : "Operand stack doesn't contain enough values";
182180
return stack.get(stack.size() - depth - 1);
183181
}
184182

@@ -191,11 +189,11 @@ void clear() {
191189
}
192190

193191
void mergeWith(OperandStack<T> other, BiFunction<T, T, T> mergeFunction) {
194-
VMError.guarantee(size() == other.size(), "Operand stack size must match upon merging");
192+
assert size() == other.size() : "Operand stack size must match upon merging";
195193
for (int i = 0; i < stack.size(); i++) {
196194
ValueWithSlots<T> thisValue = stack.get(i);
197195
ValueWithSlots<T> thatValue = other.stack.get(i);
198-
VMError.guarantee(thisValue.size() == thatValue.size(), "The size of operand stack values must match upon merging");
196+
assert thisValue.size() == thatValue.size() : "The size of operand stack values must match upon merging";
199197
ValueWithSlots<T> mergedValue = new ValueWithSlots<>(mergeFunction.apply(thisValue.value(), thatValue.value()), thisValue.size());
200198
stack.set(i, mergedValue);
201199
}
@@ -277,7 +275,7 @@ public void transform(Predicate<T> filterFunction, Function<T, T> transformFunct
277275
}
278276

279277
void put(int index, ValueWithSlots<T> value) {
280-
VMError.guarantee(index >= 0, "Local variable table index cannot be negative");
278+
assert index >= 0 : "Local variable table index cannot be negative";
281279
ValueWithSlots<T> previousInTable = variables.get(index - 1);
282280
if (previousInTable != null && previousInTable.size == ValueWithSlots.Slots.TWO_SLOTS) {
283281
/*
@@ -291,7 +289,7 @@ void put(int index, ValueWithSlots<T> value) {
291289
}
292290

293291
ValueWithSlots<T> get(int index) {
294-
VMError.guarantee(variables.containsKey(index), "Attempted to access non-existent variable in local variable table");
292+
assert variables.containsKey(index) : "Attempted to access non-existent variable in local variable table";
295293
return variables.get(index);
296294
}
297295

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/dataflow/AbstractInterpreter.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
import java.util.ArrayList;
2828
import java.util.List;
2929

30-
import com.oracle.svm.core.util.VMError;
31-
3230
import jdk.graal.compiler.bytecode.Bytecode;
3331
import jdk.graal.compiler.bytecode.BytecodeLookupSwitch;
3432
import jdk.graal.compiler.bytecode.BytecodeStream;
@@ -894,9 +892,7 @@ private enum PrimitiveTypeArrayCode {
894892

895893
static Class<?> getType(int typeCode) {
896894
int typeIndex = typeCode - TYPE_CODE_OFFSET;
897-
if (typeIndex < 0 || typeIndex >= values().length) {
898-
throw VMError.shouldNotReachHere("Unexpected primitive type code: " + typeCode);
899-
}
895+
assert typeIndex >= 0 && typeIndex < values().length : "Unexpected primitive type code: " + typeCode;
900896
return values()[typeIndex].typeClass;
901897
}
902898
}

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/dynamicaccessinference/ConstantExpressionRegistry.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import org.graalvm.collections.Pair;
3131
import org.graalvm.nativeimage.ImageSingletons;
3232

33-
import com.oracle.svm.core.util.VMError;
3433
import com.oracle.svm.util.LogUtils;
3534
import com.oracle.svm.hosted.dataflow.AbstractFrame;
3635
import com.oracle.svm.hosted.dataflow.DataFlowAnalysisException;
@@ -69,7 +68,7 @@ public ConstantExpressionRegistry() {
6968
}
7069

7170
public void analyzeAndStore(ConstantExpressionAnalyzer analyzer, ResolvedJavaMethod method, IntrinsicContext intrinsicContext) {
72-
VMError.guarantee(!isSealed(), "Registry is already sealed");
71+
assert !isSealed() : "Cannot store in registry when it is already sealed";
7372
Bytecode bytecode = getBytecode(method, intrinsicContext);
7473
try {
7574
Map<Integer, AbstractFrame<ConstantExpressionAnalyzer.Value>> abstractFrames = analyzer.analyze(bytecode);
@@ -97,8 +96,8 @@ private static Bytecode getBytecode(ResolvedJavaMethod method, IntrinsicContext
9796
* {@code null} value is represented by {@link ConstantExpressionRegistry#NULL_MARKER}.
9897
*/
9998
public Object getReceiver(ResolvedJavaMethod callerMethod, int bci, ResolvedJavaMethod targetMethod) {
100-
VMError.guarantee(!isSealed(), "Registry is already sealed");
101-
VMError.guarantee(targetMethod.hasReceiver(), "Receiver requested for static method");
99+
assert !isSealed() : "Registry is already sealed";
100+
assert targetMethod.hasReceiver() : "Method " + targetMethod + " does not have receiver";
102101
AbstractFrame<ConstantExpressionAnalyzer.Value> frame = registry.get(Pair.create(callerMethod, bci));
103102
if (frame == null) {
104103
return null;
@@ -139,9 +138,9 @@ public <T> T getReceiver(ResolvedJavaMethod callerMethod, int bci, ResolvedJavaM
139138
* {@code null} value is represented by {@link ConstantExpressionRegistry#NULL_MARKER}.
140139
*/
141140
public Object getArgument(ResolvedJavaMethod callerMethod, int bci, ResolvedJavaMethod targetMethod, int index) {
142-
VMError.guarantee(!isSealed(), "Registry is already sealed");
141+
assert !isSealed() : "Registry is already sealed";
143142
int numOfParameters = targetMethod.getSignature().getParameterCount(false);
144-
VMError.guarantee(0 <= index && index < numOfParameters, "Argument index out of bounds");
143+
assert 0 <= index && index < numOfParameters : "Argument index " + index + " out of bounds for " + targetMethod;
145144
AbstractFrame<ConstantExpressionAnalyzer.Value> frame = registry.get(Pair.create(callerMethod, bci));
146145
if (frame == null) {
147146
return null;

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/dynamicaccessinference/DynamicAccessInferenceLog.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import org.graalvm.nativeimage.ImageSingletons;
3939

4040
import com.oracle.svm.core.ParsingReason;
41-
import com.oracle.svm.core.util.VMError;
4241
import com.oracle.svm.hosted.ReachabilityRegistrationNode;
4342

4443
import jdk.graal.compiler.nodes.graphbuilderconf.GraphBuilderContext;
@@ -69,7 +68,7 @@ public void logRegistration(GraphBuilderContext b, ParsingReason reason, Resolve
6968

7069
private void logEntry(GraphBuilderContext b, ParsingReason reason, Supplier<LogEntry> entrySupplier) {
7170
if (reason.duringAnalysis() && reason != ParsingReason.JITCompilation) {
72-
VMError.guarantee(!isSealed, "Logging attempt when log is already sealed");
71+
assert !isSealed : "Logging attempt when log is already sealed";
7372
LogEntry entry = entrySupplier.get();
7473
b.add(ReachabilityRegistrationNode.create(() -> entries.add(entry), reason));
7574
}
@@ -97,8 +96,8 @@ abstract static class LogEntry {
9796
final Object[] targetArguments;
9897

9998
LogEntry(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Object targetReceiver, Object[] targetArguments) {
100-
VMError.guarantee(targetMethod.hasReceiver() == (targetReceiver != null), "Inferred receiver does not match with target method signature");
101-
VMError.guarantee(targetMethod.getSignature().getParameterCount(false) == targetArguments.length, "Inferred arguments do not match with target method signature");
99+
assert targetMethod.hasReceiver() == (targetReceiver != null) : "Inferred receiver does not match with target method signature";
100+
assert targetMethod.getSignature().getParameterCount(false) == targetArguments.length : "Inferred arguments do not match with target method signature";
102101
this.callLocation = Pair.create(b.getMethod(), b.bci());
103102
this.callStack = b.getInliningCallStack(true);
104103
this.targetMethod = targetMethod;

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/dynamicaccessinference/DynamicAccessInferenceLoggingFeature.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import java.nio.file.Path;
2929
import java.util.List;
3030

31-
import com.oracle.svm.core.util.VMError;
3231
import org.graalvm.collections.Pair;
3332
import org.graalvm.nativeimage.ImageSingletons;
3433

@@ -83,7 +82,7 @@ public void afterAnalysis(AfterAnalysisAccess access) {
8382
}
8483

8584
private void dump(String location) {
86-
VMError.guarantee(!log.isSealed(), "Attempt to access sealed log");
85+
assert !log.isSealed() : "Attempt to access sealed log";
8786
try (JsonWriter out = new JsonPrettyWriter(Path.of(location));
8887
JsonBuilder.ArrayBuilder arrayBuilder = out.arrayBuilder()) {
8988
for (DynamicAccessInferenceLog.LogEntry entry : log.getEntries()) {
@@ -101,7 +100,7 @@ private static boolean shouldWarnForNonStrictFolding() {
101100
}
102101

103102
private void warnForNonStrictFolding() {
104-
VMError.guarantee(!log.isSealed(), "Attempt to access sealed log");
103+
assert !log.isSealed() : "Attempt to access sealed log";
105104
ConstantExpressionRegistry registry = ConstantExpressionRegistry.singleton();
106105
List<DynamicAccessInferenceLog.LogEntry> unsafeFoldingEntries = log.getEntries().stream().filter(entry -> !registryContainsConstantOperands(registry, entry)).toList();
107106
if (!unsafeFoldingEntries.isEmpty()) {

0 commit comments

Comments
 (0)