Skip to content

Commit

Permalink
Downstream ForgeFlower#105
Browse files Browse the repository at this point in the history
Co-authored-by: coehlrich <[email protected]>
  • Loading branch information
jaskarth and coehlrich committed Aug 1, 2023
1 parent b16b459 commit d88f743
Show file tree
Hide file tree
Showing 27 changed files with 159 additions and 191 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,7 @@ private boolean compareBasicBlocksEx(ControlFlowGraph graph,
List<int[]> lstStoreVars) {
InstructionSequence seqPattern = pattern.getSeq();
InstructionSequence seqSample = sample.getSeq();
List<Integer> instrOldOffsetsSample = sample.getInstrOldOffsets();

if (type != 0) {
seqPattern = seqPattern.clone();
Expand Down Expand Up @@ -822,6 +823,7 @@ private boolean compareBasicBlocksEx(ControlFlowGraph graph,
seq.addInstruction(0, seqSample.getInstr(i), -1);
oldOffsets.addFirst(sample.getOldOffset(i));
seqSample.removeInstruction(i);
instrOldOffsetsSample.remove(i);
}

BasicBlock newblock = new BasicBlock(++graph.last_id);
Expand Down Expand Up @@ -1010,26 +1012,31 @@ private static void deleteArea(ControlFlowGraph graph, Area area) {

private static void removeExceptionInstructionsEx(BasicBlock block, int blocktype, int finallytype) {
InstructionSequence seq = block.getSeq();
List<Integer> instrOldOffsets = block.getInstrOldOffsets();

if (finallytype == 3) { // empty finally handler
for (int i = seq.length() - 1; i >= 0; i--) {
seq.removeInstruction(i);
instrOldOffsets.remove(i);
}
}
else {
if ((blocktype & 1) > 0) { // first
if (finallytype == 2 || finallytype == 1) { // astore or pop
seq.removeInstruction(0);
instrOldOffsets.remove(0);
}
}

if ((blocktype & 2) > 0) { // last
if (finallytype == 2 || finallytype == 0) {
seq.removeLast();
instrOldOffsets.remove(instrOldOffsets.size() - 1);
}

if (finallytype == 2) { // astore
seq.removeLast();
instrOldOffsets.remove(instrOldOffsets.size() - 1);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions test/org/jetbrains/java/decompiler/SingleClassesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ private void registerDefault() {
register(JAVA_8, "TestAnonymousClassConstructor");
register(JAVA_8, "TestInnerClassConstructor");
register(CUSTOM, "v11/TestInnerClassConstructor");
// [minor] todo: the linenumbers are incorrect on the finally block
register(JAVA_8, "TestTryCatchFinally");
register(JAVA_8, "TestTryFinally");
register(JAVA_8, "TestAmbiguousCall");
Expand Down
19 changes: 11 additions & 8 deletions testData/results/TestHotjava.dec
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ public class TestHotjava {
try {
System.out.println("Try");// 7 8
} finally {
System.out.println("Jsr");
System.out.println("Jsr");// 10
}
}// 10
}

// $VF: Could not inline inconsistent finally blocks
// $VF: Could not create synchronized statement, marking monitor enters and exits
Expand Down Expand Up @@ -50,7 +50,7 @@ public class TestHotjava {
try {
System.out.println("Try");// 28 29
} finally {
System.out.println("Jsr");
System.out.println("Jsr");// 31
}
} catch (Throwable var10) {
// $VF: monitorexit
Expand Down Expand Up @@ -81,13 +81,15 @@ class 'TestHotjava' {
3 7
4 7
5 7
c 9
d 9
e 9
f 9
10 9
11 9
12 9
13 9
14 9
15 9
18 11
}

Expand Down Expand Up @@ -133,14 +135,16 @@ class 'TestHotjava' {
7 50
8 50
9 50
12 52
13 52
14 52
15 52
16 52
17 52
18 52
19 52
1a 52
1b 52
1c 52
25 59
26 60
28 55
Expand All @@ -153,13 +157,12 @@ Lines mapping:
3 <-> 3
7 <-> 8
8 <-> 8
10 <-> 12
10 <-> 10
15 <-> 17
16 <-> 20
21 <-> 32
22 <-> 35
27 <-> 47
28 <-> 51
29 <-> 51
Not mapped:
31
31 <-> 53
10 changes: 6 additions & 4 deletions testData/results/TestJsr.dec
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ public class TestJsr {
try {
System.out.println("Test");// 3 4
} finally {
System.out.println("Jsr");
System.out.println("Jsr");// 6
}
}// 6
}
}

class 'TestJsr' {
Expand All @@ -16,18 +16,20 @@ class 'TestJsr' {
3 3
4 3
5 3
c 5
d 5
e 5
f 5
10 5
11 5
12 5
13 5
14 5
15 5
18 7
}
}

Lines mapping:
3 <-> 4
4 <-> 4
6 <-> 8
6 <-> 6
4 changes: 2 additions & 2 deletions testData/results/pkg/TestClassLoop.dec
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ class 'pkg/TestClassLoop' {
e 14
f 14
1a 15
26 18
27 18
28 18
29 18
2a 18
2b 18
2c 18
}

method 'testCatch ()V' {
Expand Down Expand Up @@ -168,8 +168,8 @@ class 'pkg/TestClassLoop' {
11 43
12 43
13 43
25 46
26 46
27 46
2a 47
2b 47
2c 47
Expand Down
2 changes: 1 addition & 1 deletion testData/results/pkg/TestClassSimpleBytecodeMapping.dec
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ class 'pkg/TestClassSimpleBytecodeMapping' {
13 25
14 25
15 25
23 27
24 27
25 27
26 27
27 27
28 27
29 27
2e 29
}

Expand Down
2 changes: 1 addition & 1 deletion testData/results/pkg/TestClassVar.dec
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ class 'pkg/TestClassVar' {
9 9
a 9
b 9
1e 11
1f 11
20 11
21 11
22 11
23 11
26 12
27 12
28 12
Expand Down
22 changes: 8 additions & 14 deletions testData/results/pkg/TestComplexIfElseChain.dec
Original file line number Diff line number Diff line change
Expand Up @@ -1036,8 +1036,8 @@ class 'pkg/TestComplexIfElseChain' {
12 201
13 201
14 201
83 203
84 203
85 203
88 203
89 203
8a 203
Expand Down Expand Up @@ -1125,8 +1125,8 @@ class 'pkg/TestComplexIfElseChain' {
12 222
13 222
14 222
83 224
84 224
85 224
88 224
89 224
8a 224
Expand Down Expand Up @@ -1285,9 +1285,8 @@ class 'pkg/TestComplexIfElseChain' {
12 255
13 255
14 255
f9 257
fa 257
fb 257
fc 257
ff 257
100 257
101 257
Expand All @@ -1297,13 +1296,12 @@ class 'pkg/TestComplexIfElseChain' {
107 259
108 259
109 259
117 261
118 261
119 261
11a 261
11b 261
11c 261
11d 261
11e 261
127 263
128 263
129 263
Expand All @@ -1316,13 +1314,12 @@ class 'pkg/TestComplexIfElseChain' {
134 265
135 265
136 265
144 267
145 267
146 267
147 267
148 267
149 267
14a 267
14b 267
154 269
155 269
156 269
Expand All @@ -1335,13 +1332,12 @@ class 'pkg/TestComplexIfElseChain' {
161 271
162 271
163 271
171 273
172 273
173 273
174 273
175 273
176 273
177 273
178 273
181 275
182 275
183 275
Expand All @@ -1356,13 +1352,12 @@ class 'pkg/TestComplexIfElseChain' {
190 277
191 277
192 277
1a0 279
1a1 279
1a2 279
1a3 279
1a4 279
1a5 279
1a6 279
1a7 279
1b0 281
1b1 281
1b2 281
Expand All @@ -1377,13 +1372,12 @@ class 'pkg/TestComplexIfElseChain' {
1bf 283
1c0 283
1c1 283
1cf 285
1d0 285
1d1 285
1d2 285
1d3 285
1d4 285
1d5 285
1d6 285
1df 289
}
}
Expand Down
5 changes: 2 additions & 3 deletions testData/results/pkg/TestFinallyBlockVariableUse.dec
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,14 @@ class 'pkg/TestFinallyBlockVariableUse' {
4d 15
4e 15
4f 15
50 18
51 18
52 18
53 18
54 18
55 18
56 19
56 18
57 19
58 19
59 19
5c 20
63 20
64 20
Expand Down
3 changes: 1 addition & 2 deletions testData/results/pkg/TestFinallyThrow.dec
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,11 @@ class 'pkg/TestFinallyThrow' {
47 14
48 14
49 14
4a 16
4b 16
4c 16
4d 16
4e 16
4f 16
50 16
}

method 'test1 (Ljava/lang/RuntimeException;)V' {
Expand Down
18 changes: 9 additions & 9 deletions testData/results/pkg/TestIfElseTernary1.dec
Original file line number Diff line number Diff line change
Expand Up @@ -605,22 +605,22 @@ class 'pkg/TestIfElseTernary1' {
a3 108
a4 108
ae 111
af 113
b0 113
b1 113
b2 113
b4 114
b5 114
b9 114
b3 113
b6 114
b7 114
b8 114
ba 114
bb 115
bb 114
bc 115
bd 115
be 115
bf 115
c7 116
c8 116
c9 116
c0 115
c1 115
c2 115
ca 116
}
}

Expand Down
Loading

0 comments on commit d88f743

Please sign in to comment.