From 804b51abf5355fd880c8cb30e83b0c3874ddf795 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Wed, 21 Oct 2015 18:45:37 +0300 Subject: [PATCH] Fix bug in method submit API --- .../org/teavm/dependency/DataFlowGraphBuilder.java | 6 +++--- .../java/org/teavm/dependency/DependencyChecker.java | 11 ++++++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/teavm/dependency/DataFlowGraphBuilder.java b/core/src/main/java/org/teavm/dependency/DataFlowGraphBuilder.java index 3e52c364d..4eaec8708 100644 --- a/core/src/main/java/org/teavm/dependency/DataFlowGraphBuilder.java +++ b/core/src/main/java/org/teavm/dependency/DataFlowGraphBuilder.java @@ -216,7 +216,7 @@ public class DataFlowGraphBuilder implements InstructionReader { @Override public void exit(VariableReader valueToReturn) { if (valueToReturn != null && returnIndex >= 0) { - connect(valueToReturn.getIndex(), returnIndex); + builder.addEdge(valueToReturn.getIndex(), returnIndex); } } @@ -253,7 +253,7 @@ public class DataFlowGraphBuilder implements InstructionReader { if (fieldType instanceof ValueType.Primitive) { return; } - connect(getFieldNode(field), receiver.getIndex()); + builder.addEdge(getFieldNode(field), receiver.getIndex()); } @Override @@ -261,7 +261,7 @@ public class DataFlowGraphBuilder implements InstructionReader { if (fieldType instanceof ValueType.Primitive) { return; } - connect(value.getIndex(), getFieldNode(field)); + builder.addEdge(value.getIndex(), getFieldNode(field)); } @Override diff --git a/core/src/main/java/org/teavm/dependency/DependencyChecker.java b/core/src/main/java/org/teavm/dependency/DependencyChecker.java index 27a742e0b..7a40a6992 100644 --- a/core/src/main/java/org/teavm/dependency/DependencyChecker.java +++ b/core/src/main/java/org/teavm/dependency/DependencyChecker.java @@ -51,6 +51,7 @@ import org.teavm.model.Program; import org.teavm.model.ValueType; import org.teavm.model.util.ModelUtils; import org.teavm.model.util.ProgramUtils; +import org.teavm.optimization.UnreachableBasicBlockEliminator; /** * @@ -177,12 +178,20 @@ public class DependencyChecker implements DependencyInfo { if (!method.hasModifier(ElementModifier.NATIVE)) { throw new IllegalArgumentException("Method is not native: " + methodRef); } + if (!dep.used) { + return; + } method.getModifiers().remove(ElementModifier.NATIVE); method.setProgram(ProgramUtils.copy(program)); + new UnreachableBasicBlockEliminator().optimize(method.getProgram()); dep.used = false; lock(dep, false); - scheduleMethodAnalysis(dep); + tasks.add(() -> { + DependencyGraphBuilder graphBuilder = new DependencyGraphBuilder(DependencyChecker.this); + graphBuilder.buildGraph(dep); + dep.used = true; + }); processQueue(); }