Skip to content

Commit ea5d1d1

Browse files
authored
fixed dead code patching in StackMapGenerator::removeRangeFromExcTable and added test (openjdk#10)
1 parent e924489 commit ea5d1d1

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

src/java.base/share/classes/jdk/classfile/impl/StackMapGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ private void removeRangeFromExcTable(int rangeStart, int rangeEnd) {
360360
int handlerEnd = labelContext.labelToBci(e.tryEnd());
361361
if (rangeStart >= handlerEnd || rangeEnd <= handlerStart) {
362362
//out of range
363-
return;
363+
continue;
364364
}
365365
if (trace) System.out.println(" Removing dead code range from exception handler start: " + handlerStart + " end: " + handlerEnd);
366366
if (rangeStart <= handlerStart) {

test/jdk/jdk/classfile/StackMapsTest.java

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,36 @@ private byte[] buildDeadCode() {
5555
ClassDesc.of("DeadCodePattern"),
5656
List.of(Classfile.Option.generateStackmap(false), Classfile.Option.patchDeadCode(false)),
5757
clb -> clb.withMethodBody(
58-
"twoReturns",
59-
MethodTypeDesc.of(ConstantDescs.CD_void),
60-
0,
61-
cob -> cob.return_().return_()));
58+
"twoReturns",
59+
MethodTypeDesc.of(ConstantDescs.CD_void),
60+
0,
61+
cob -> cob.return_().return_())
62+
.withMethodBody(
63+
"deadJumpInExceptionBlocks",
64+
MethodTypeDesc.of(ConstantDescs.CD_void),
65+
0,
66+
cob -> {
67+
var deadEnd = cob.newLabel();
68+
cob.goto_(deadEnd);
69+
var deadStart = cob.newBoundLabel();
70+
cob.return_(); //dead code
71+
cob.labelBinding(deadEnd);
72+
cob.return_();
73+
var handler = cob.newBoundLabel();
74+
cob.athrow();
75+
//exception block before dead code to stay untouched
76+
cob.exceptionCatch(cob.startLabel(), deadStart, handler, ConstantDescs.CD_Throwable);
77+
//exception block after dead code to stay untouched
78+
cob.exceptionCatch(deadEnd, handler, handler, ConstantDescs.CD_Throwable);
79+
//exception block overlapping dead code to cut from right
80+
cob.exceptionCatch(cob.startLabel(), deadEnd, handler, ConstantDescs.CD_Throwable);
81+
//exception block overlapping dead code to from left
82+
cob.exceptionCatch(deadStart, handler, handler, ConstantDescs.CD_Throwable);
83+
//exception block matching dead code to remove
84+
cob.exceptionCatch(deadStart, deadEnd, handler, ConstantDescs.CD_Throwable);
85+
//exception block around dead code to split
86+
cob.exceptionCatch(cob.startLabel(), handler, handler, ConstantDescs.CD_Throwable);
87+
}));
6288
}
6389

6490
@Test

0 commit comments

Comments
 (0)