Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test break statements within try statements #10

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -2248,7 +2248,7 @@ public Block.Builder lower(Block.Builder b, OpTransformer opT) {

boolean ifExitFromTry(JavaLabelOp lop) {
Op target = lop.target();
return ifAncestorOp(target, this);
return target == this || ifAncestorOp(target, this);
}

static boolean ifAncestorOp(Op ancestor, Op op) {
77 changes: 77 additions & 0 deletions test/jdk/java/lang/reflect/code/TestTryFinallyNested.java
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@
import org.testng.Assert;
import org.testng.annotations.Test;

import java.lang.reflect.code.analysis.SSA;
import java.lang.reflect.code.op.CoreOps;
import java.lang.reflect.code.Op;
import java.lang.reflect.code.interpreter.Interpreter;
@@ -119,6 +120,82 @@ public void testCatchFinally() {
}


@CodeReflection
public static void tryCatchFinallyBreak(IntConsumer c, int i) {
a: try {
try {
if (i == 0) {
break a;
}
c.accept(0);
} catch (IllegalStateException e) {
if (i == 1) {
break a;
}
c.accept(1);
} finally {
if (i == 2) {
break a;
}
c.accept(2);
}
if (i == 3) {
break a;
}
c.accept(3);
} catch (IllegalStateException e) {
if (i == 4) {
break a;
}
c.accept(4);
} finally {
if (i == 5) {
break a;
}
c.accept(5);
}
c.accept(6);
}

@Test
public void testCatchFinallyBreak() {
CoreOps.FuncOp f = getFuncOp("tryCatchFinallyBreak");

f.writeTo(System.out);

CoreOps.FuncOp lf = f.transform((block, op) -> {
if (op instanceof Op.Lowerable lop) {
return lop.lower(block);
} else {
block.op(op);
return block;
}
});

lf.writeTo(System.out);

for (int ra = -1; ra < 6; ra++) {
int fra = ra;

Consumer<IntConsumer> test = testConsumer(
c -> Interpreter.invoke(MethodHandles.lookup(), lf, c, fra),
c -> tryCatchFinallyBreak(c, fra)
);

test.accept(i -> {});
for (int ea = 0; ea < 6; ea++) {
int fea = ea;
test.accept(i -> {
if (i == fea) throw new IllegalStateException();
});
test.accept(i -> {
if (i == fea) throw new RuntimeException();
});
}
}
}


@CodeReflection
public static void tryForLoop(IntConsumer c) {
for (int i = 0; i < 8; i++) {