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')); .create('c'));
options.addOption(OptionBuilder options.addOption(OptionBuilder
.withDescription("Wait for command after compilation, in order to enable hot recompilation") .withDescription("Wait for command after compilation, in order to enable hot recompilation")
.withLongOpt("--wait") .withLongOpt("wait")
.create('w')); .create('w'));
options.addOption(OptionBuilder options.addOption(OptionBuilder
.withArgName("classpath") .withArgName("classpath")
.hasArgs() .hasArgs()
.withDescription("Additional classpath that will be reloaded by TeaVM each time in wait mode") .withDescription("Additional classpath that will be reloaded by TeaVM each time in wait mode")
.withLongOpt("--classpath") .withLongOpt("classpath")
.create('p')); .create('p'));
if (args.length == 0) { if (args.length == 0) {

View File

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

View File

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