Fix bugs in optimized try/catch decompiler

This commit is contained in:
Alexey Andreev 2015-04-15 20:18:05 +03:00
parent 1f5c5ce85e
commit 4b4af6dd4e
3 changed files with 15 additions and 7 deletions

View File

@ -93,13 +93,13 @@ public final class TeaVMRunner {
.create('c'));
options.addOption(OptionBuilder
.withDescription("Wait for command after compilation, in order to enable hot recompilation")
.withLongOpt("--wait")
.withLongOpt("wait")
.create('w'));
options.addOption(OptionBuilder
.withArgName("classpath")
.hasArgs()
.withDescription("Additional classpath that will be reloaded by TeaVM each time in wait mode")
.withLongOpt("--classpath")
.withLongOpt("classpath")
.create('p'));
if (args.length == 0) {

View File

@ -143,9 +143,9 @@ class BreakEliminator implements StatementVisitor {
outerStatements = new HashSet<>();
blockSuccessors = new HashMap<>();
processSequence(statement.getProtectedBody());
processSequence(statement.getHandler());
outerStatements = oldOuterStatements;
blockSuccessors = oldBlockSuccessors;
processSequence(statement.getHandler());
}
@Override

View File

@ -289,7 +289,7 @@ public class Decompiler {
private AsyncMethodPart getRegularMethodStatement(Program program, int[] targetBlocks, boolean async) {
AsyncMethodPart result = new AsyncMethodPart();
lastBlockId = 1;
graph = ProgramUtils.buildControlFlowGraph(program);
graph = ProgramUtils.buildControlFlowGraphWithTryCatch(program);
int[] weights = new int[graph.size()];
for (int i = 0; i < weights.length; ++i) {
weights[i] = program.basicBlockAt(i).getInstructions().size();
@ -349,7 +349,9 @@ public class Decompiler {
List<Statement> blockPart = oldBlock.body.subList(bookmark.offset, oldBlock.body.size());
tryCatchStmt.getProtectedBody().addAll(blockPart);
blockPart.clear();
if (!tryCatchStmt.getProtectedBody().isEmpty()) {
blockPart.add(tryCatchStmt);
}
inheritedBookmarks.add(bookmark);
}
oldBlock.tryCatches.clear();
@ -439,7 +441,9 @@ public class Decompiler {
program.basicBlockAt(bookmark.exceptionHandler)));
tryCatchStmt.getProtectedBody().addAll(block.body);
block.body.clear();
if (!tryCatchStmt.getProtectedBody().isEmpty()) {
block.body.add(tryCatchStmt);
}
block = block.parent;
}
@ -451,11 +455,15 @@ public class Decompiler {
List<Statement> blockPart = block.body.subList(bookmark.offset, block.body.size());
tryCatchStmt.getProtectedBody().addAll(blockPart);
blockPart.clear();
if (!tryCatchStmt.getProtectedBody().isEmpty()) {
blockPart.add(tryCatchStmt);
}
bookmark.block.tryCatches.remove(bookmark);
}
tryCatchBookmarks.subList(start, tryCatchBookmarks.size()).clear();
// Add new bookmarks
for (int i = start; i < tryCatchBlocks.size(); ++i) {
TryCatchBlock tryCatch = tryCatchBlocks.get(i);