Skip to content

Commit fda115b

Browse files
committed
[GR-10670] Corrupt frame state when handling deleted fields with --report-unsupported-elements-at-runtime.
PullRequest: graal/1766
2 parents ba654b7 + a3a4a0b commit fda115b

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

compiler/src/org.graalvm.compiler.java/src/org/graalvm/compiler/java/BytecodeParser.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3543,6 +3543,11 @@ public void push(JavaKind slotKind, ValueNode value) {
35433543
frameState.push(slotKind, value);
35443544
}
35453545

3546+
@Override
3547+
public ValueNode pop(JavaKind slotKind) {
3548+
return frameState.pop(slotKind);
3549+
}
3550+
35463551
@Override
35473552
public ConstantReflectionProvider getConstantReflection() {
35483553
return constantReflection;

compiler/src/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/graphbuilderconf/GraphBuilderContext.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.graalvm.compiler.core.common.type.Stamp;
3636
import org.graalvm.compiler.core.common.type.StampFactory;
3737
import org.graalvm.compiler.core.common.type.StampPair;
38+
import org.graalvm.compiler.debug.GraalError;
3839
import org.graalvm.compiler.nodes.AbstractMergeNode;
3940
import org.graalvm.compiler.nodes.CallTargetNode;
4041
import org.graalvm.compiler.nodes.CallTargetNode.InvokeKind;
@@ -76,6 +77,16 @@ public interface GraphBuilderContext extends GraphBuilderTool {
7677
*/
7778
void push(JavaKind kind, ValueNode value);
7879

80+
/**
81+
* Pops a value from the frame state stack using an explicit kind.
82+
*
83+
* @param slotKind the kind to use when type checking this operation
84+
* @return the value on the top of the stack
85+
*/
86+
default ValueNode pop(JavaKind slotKind) {
87+
throw GraalError.unimplemented();
88+
}
89+
7990
/**
8091
* Adds a node to the graph. If the node is in the graph, returns immediately. If the node is a
8192
* {@link StateSplit} with a null {@linkplain StateSplit#stateAfter() frame state}, the frame

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/DeletedFieldsPlugin.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,39 +33,52 @@
3333
import com.oracle.svm.core.annotate.Delete;
3434
import com.oracle.svm.core.meta.SubstrateObjectConstant;
3535

36+
import jdk.vm.ci.meta.JavaKind;
3637
import jdk.vm.ci.meta.ResolvedJavaField;
38+
import jdk.vm.ci.meta.ResolvedJavaMethod;
3739

3840
public final class DeletedFieldsPlugin implements NodePlugin {
3941

4042
@Override
4143
public boolean handleLoadField(GraphBuilderContext b, ValueNode object, ResolvedJavaField field) {
42-
return handleField(b, field);
44+
return handleField(b, field, true);
4345
}
4446

4547
@Override
4648
public boolean handleLoadStaticField(GraphBuilderContext b, ResolvedJavaField field) {
47-
return handleField(b, field);
49+
return handleField(b, field, true);
4850
}
4951

5052
@Override
5153
public boolean handleStoreField(GraphBuilderContext b, ValueNode object, ResolvedJavaField field, ValueNode value) {
52-
return handleField(b, field);
54+
return handleField(b, field, false);
5355
}
5456

5557
@Override
5658
public boolean handleStoreStaticField(GraphBuilderContext b, ResolvedJavaField field, ValueNode value) {
57-
return handleField(b, field);
59+
return handleField(b, field, false);
5860
}
5961

60-
private static boolean handleField(GraphBuilderContext b, ResolvedJavaField field) {
62+
private static boolean handleField(GraphBuilderContext b, ResolvedJavaField field, boolean isLoad) {
6163
Delete deleteAnnotation = field.getAnnotation(Delete.class);
6264
if (deleteAnnotation == null) {
6365
return false;
6466
}
6567

6668
String msg = AnnotationSubstitutionProcessor.deleteErrorMessage(field, deleteAnnotation, false);
6769
ValueNode msgNode = ConstantNode.forConstant(SubstrateObjectConstant.forObject(msg), b.getMetaAccess(), b.getGraph());
68-
b.handleReplacedInvoke(InvokeKind.Static, b.getMetaAccess().lookupJavaMethod(DeletedMethod.reportErrorMethod), new ValueNode[]{msgNode}, false);
70+
ResolvedJavaMethod reportErrorMethod = b.getMetaAccess().lookupJavaMethod(DeletedMethod.reportErrorMethod);
71+
b.handleReplacedInvoke(InvokeKind.Static, reportErrorMethod, new ValueNode[]{msgNode}, false);
72+
73+
JavaKind returnKind = reportErrorMethod.getSignature().getReturnKind();
74+
if (returnKind != JavaKind.Void) {
75+
b.pop(returnKind);
76+
}
77+
if (isLoad) {
78+
// Push dummy value.
79+
b.addPush(field.getJavaKind(), ConstantNode.defaultForKind(field.getJavaKind()));
80+
}
81+
6982
return true;
7083
}
7184
}

0 commit comments

Comments
 (0)