Skip to content

Commit

Permalink
[GR-54203] Fail at image run time instead of image build time for com…
Browse files Browse the repository at this point in the history
…plicated JSR-RET structures.

PullRequest: graal/18022
  • Loading branch information
christianwimmer committed Jun 18, 2024
2 parents 139f165 + 46e2125 commit 81d23df
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3080,10 +3080,12 @@ protected void genJsr(int dest) {
JsrScope scope = currentBlock.getJsrScope();
int nextBci = getStream().nextBCI();
if (!successor.getJsrScope().pop().equals(scope)) {
throw new JsrNotSupportedBailout("unstructured control flow (internal limitation)");
handleUnsupportedJsr("unstructured control flow (internal limitation)");
return;
}
if (successor.getJsrScope().nextReturnAddress() != nextBci) {
throw new JsrNotSupportedBailout("unstructured control flow (internal limitation)");
handleUnsupportedJsr("unstructured control flow (internal limitation)");
return;
}
ConstantNode nextBciNode = getJsrConstant(nextBci);
frameState.push(JavaKind.Object, nextBciNode);
Expand All @@ -3098,14 +3100,20 @@ protected void genRet(int localIndex) {
ConstantNode returnBciNode = getJsrConstant(retAddress);
LogicNode guard = IntegerEqualsNode.create(getConstantReflection(), getMetaAccess(), options, null, local, returnBciNode, NodeView.DEFAULT);
if (!guard.isTautology()) {
throw new JsrNotSupportedBailout("cannot statically decide jsr return address " + local);
handleUnsupportedJsr("cannot statically decide jsr return address " + local);
return;
}
if (!successor.getJsrScope().equals(scope.pop())) {
throw new JsrNotSupportedBailout("unstructured control flow (ret leaves more than one scope)");
handleUnsupportedJsr("unstructured control flow (ret leaves more than one scope)");
return;
}
appendGoto(successor);
}

protected void handleUnsupportedJsr(String msg) {
throw new JsrNotSupportedBailout(msg);
}

private ConstantNode getJsrConstant(long bci) {
JavaConstant nextBciConstant = new RawConstant(bci);
Stamp nextBciStamp = StampFactory.forConstant(nextBciConstant);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@
import jdk.graal.compiler.nodes.calc.IsNullNode;
import jdk.graal.compiler.nodes.extended.BoxNode;
import jdk.graal.compiler.nodes.extended.BranchProbabilityNode;
import jdk.graal.compiler.nodes.extended.BytecodeExceptionNode.BytecodeExceptionKind;
import jdk.graal.compiler.nodes.extended.ForeignCallNode;
import jdk.graal.compiler.nodes.extended.UnboxNode;
import jdk.graal.compiler.nodes.extended.BytecodeExceptionNode.BytecodeExceptionKind;
import jdk.graal.compiler.nodes.graphbuilderconf.GeneratedInvocationPlugin;
import jdk.graal.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
import jdk.graal.compiler.nodes.graphbuilderconf.GraphBuilderPlugin;
Expand Down Expand Up @@ -656,6 +656,11 @@ protected int minLockDepthAtMonitorExit(boolean inEpilogue) {
return 1;
}

@Override
protected void handleUnsupportedJsr(String msg) {
genThrowUnsupportedFeatureError(msg);
}

@Override
protected void handleUnstructuredLocking(String msg, boolean isDeadEnd) {
ValueNode methodSynchronizedObjectSnapshot = methodSynchronizedObject;
Expand Down Expand Up @@ -783,13 +788,11 @@ private void genReleaseMonitors(boolean includeMethodSynchronizeObject) {
}

private void genThrowUnsupportedFeatureError(String msg) {
FixedNode unreachableNode = graph.add(new LoweredDeadEndNode());

ConstantNode messageNode = ConstantNode.forConstant(getConstantReflection().forString(msg), getMetaAccess(), getGraph());
ForeignCallNode foreignCallNode = graph.add(new ForeignCallNode(SnippetRuntime.UNSUPPORTED_FEATURE, messageNode));
foreignCallNode.setNext(unreachableNode);
unreachableNode = foreignCallNode;
lastInstr.setNext(unreachableNode);
lastInstr.setNext(foreignCallNode);
foreignCallNode.setNext(graph.add(new LoweredDeadEndNode()));
lastInstr = null;
}

private void checkWordType(ValueNode value, JavaType expectedType, String reason) {
Expand Down

0 comments on commit 81d23df

Please sign in to comment.