diff --git a/core/src/main/java/org/teavm/dependency/DependencyAnalyzer.java b/core/src/main/java/org/teavm/dependency/DependencyAnalyzer.java index e445eb3ee..25c818223 100644 --- a/core/src/main/java/org/teavm/dependency/DependencyAnalyzer.java +++ b/core/src/main/java/org/teavm/dependency/DependencyAnalyzer.java @@ -429,7 +429,7 @@ public class DependencyAnalyzer implements DependencyInfo { parameterNodes[i + 1] = createNode(arguments[i]); parameterNodes[i + 1].method = methodRef; if (shouldTag) { - parameterNodes[i].setTag(methodRef + ":" + i); + parameterNodes[i + 1].setTag(methodRef + ":" + (i + 1)); } } diff --git a/core/src/main/java/org/teavm/dependency/DependencyNode.java b/core/src/main/java/org/teavm/dependency/DependencyNode.java index fb86b77d3..3109e2401 100644 --- a/core/src/main/java/org/teavm/dependency/DependencyNode.java +++ b/core/src/main/java/org/teavm/dependency/DependencyNode.java @@ -21,6 +21,7 @@ import org.teavm.model.ValueType; public class DependencyNode implements ValueDependencyInfo { private static final int SMALL_TYPES_THRESHOLD = 3; + private static final int DEGREE_THRESHOLD = 2; private DependencyAnalyzer dependencyAnalyzer; private List followers; private int[] smallTypes; @@ -89,7 +90,7 @@ public class DependencyNode implements ValueDependencyInfo { } public void propagate(DependencyType type) { - if (degree > 2) { + if (degree > DEGREE_THRESHOLD) { return; } if (addType(type) && filter(type)) { @@ -102,20 +103,20 @@ public class DependencyNode implements ValueDependencyInfo { private void scheduleSingleType(DependencyType type) { if (followers != null) { - for (DependencyConsumer consumer : followers.toArray(new DependencyConsumer[0])) { + for (DependencyConsumer consumer : followers.toArray(new DependencyConsumer[followers.size()])) { dependencyAnalyzer.schedulePropagation(consumer, type); } } if (transitions != null) { for (DependencyNodeToNodeTransition consumer : transitions.values().toArray( - new DependencyNodeToNodeTransition[0])) { + new DependencyNodeToNodeTransition[transitions.size()])) { dependencyAnalyzer.schedulePropagation(consumer, type); } } } public void propagate(DependencyType[] newTypes) { - if (degree > 2) { + if (degree > DEGREE_THRESHOLD) { return; } @@ -213,6 +214,19 @@ public class DependencyNode implements ValueDependencyInfo { } propagateTypes(transition); + + if (degree <= DEGREE_THRESHOLD && node.degree <= DEGREE_THRESHOLD) { + if (arrayItemNode != null && node.arrayItemNode == null) { + node.arrayItemNode = arrayItemNode; + } else if (node.arrayItemNode != null && arrayItemNode == null) { + arrayItemNode = node.arrayItemNode; + } else if (node.arrayItemNode == null && arrayItemNode == null) { + node.arrayItemNode = getArrayItem(); + } else { + arrayItemNode.connect(node.arrayItemNode); + node.arrayItemNode.connect(arrayItemNode); + } + } } private void propagateTypes(DependencyConsumer transition) { diff --git a/core/src/main/java/org/teavm/dependency/DependencyNodeToNodeTransition.java b/core/src/main/java/org/teavm/dependency/DependencyNodeToNodeTransition.java index f1d6e82bb..e381dc89e 100644 --- a/core/src/main/java/org/teavm/dependency/DependencyNodeToNodeTransition.java +++ b/core/src/main/java/org/teavm/dependency/DependencyNodeToNodeTransition.java @@ -34,16 +34,7 @@ class DependencyNodeToNodeTransition implements DependencyConsumer { @Override public void consume(DependencyType type) { - if (type.getName().startsWith("[")) { - if (!filterType(type)) { - return; - } - source.getArrayItem().connect(destination.getArrayItem()); - destination.getArrayItem().connect(source.getArrayItem()); - if (!destination.hasType(type)) { - destination.propagate(type); - } - } else if (type.getName().equals("java.lang.Class")) { + if (type.getName().equals("java.lang.Class")) { if (!filterType(type)) { return; } @@ -70,10 +61,6 @@ class DependencyNodeToNodeTransition implements DependencyConsumer { added = true; } - if (type.getName().startsWith("[")) { - source.getArrayItem().connect(destination.getArrayItem()); - destination.getArrayItem().connect(source.getArrayItem()); - } if (type.getName().equals("java.lang.Class")) { source.getClassValueNode().connect(destination.getClassValueNode()); } @@ -91,10 +78,6 @@ class DependencyNodeToNodeTransition implements DependencyConsumer { added = true; } - if (type.getName().startsWith("[")) { - source.getArrayItem().connect(destination.getArrayItem()); - destination.getArrayItem().connect(source.getArrayItem()); - } if (type.getName().equals("java.lang.Class")) { source.getClassValueNode().connect(destination.getClassValueNode()); } @@ -121,7 +104,7 @@ class DependencyNodeToNodeTransition implements DependencyConsumer { } } - private boolean filterType(DependencyType type) { + boolean filterType(DependencyType type) { if (filter == null) { return true; }