From 2f95045345df56ec4e94b6cd9ab267cde891ef73 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Fri, 28 Feb 2020 14:42:51 +0300 Subject: [PATCH] Improve optimization of unused methods that were inlined on every usage --- .../ExpressionSideEffectDecomposer.java | 2 +- .../org/teavm/dependency/VirtualCallConsumer.java | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/teavm/ast/optimization/ExpressionSideEffectDecomposer.java b/core/src/main/java/org/teavm/ast/optimization/ExpressionSideEffectDecomposer.java index 1c30d56d1..acd146a02 100644 --- a/core/src/main/java/org/teavm/ast/optimization/ExpressionSideEffectDecomposer.java +++ b/core/src/main/java/org/teavm/ast/optimization/ExpressionSideEffectDecomposer.java @@ -36,7 +36,7 @@ public class ExpressionSideEffectDecomposer extends RecursiveVisitor { public void visit(ConditionalExpr expr) { ConditionalStatement statement = new ConditionalStatement(); statement.setCondition(expr.getCondition()); - expr.getCondition().acceptVisitor(new ExpressionSideEffectDecomposer(statement.getConsequent())); + expr.getConsequent().acceptVisitor(new ExpressionSideEffectDecomposer(statement.getConsequent())); expr.getAlternative().acceptVisitor(new ExpressionSideEffectDecomposer(statement.getAlternative())); target.add(statement); } diff --git a/core/src/main/java/org/teavm/dependency/VirtualCallConsumer.java b/core/src/main/java/org/teavm/dependency/VirtualCallConsumer.java index e71fdbeee..4c0a45abb 100644 --- a/core/src/main/java/org/teavm/dependency/VirtualCallConsumer.java +++ b/core/src/main/java/org/teavm/dependency/VirtualCallConsumer.java @@ -29,6 +29,8 @@ class VirtualCallConsumer implements DependencyConsumer { private final BitSet knownTypes = new BitSet(); private DependencyGraphBuilder.ExceptionConsumer exceptionConsumer; private DependencyTypeFilter filter; + private boolean isPolymorphic; + private MethodDependency monomorphicCall; VirtualCallConsumer(DependencyNode node, String filterClass, MethodDescriptor methodDesc, DependencyAnalyzer analyzer, DependencyNode[] parameters, @@ -67,7 +69,17 @@ class VirtualCallConsumer implements DependencyConsumer { MethodDependency methodDep = analyzer.linkMethod(className, methodDesc); methodDep.addLocation(location); if (!methodDep.isMissing()) { - methodDep.use(); + methodDep.use(false); + if (isPolymorphic) { + methodDep.external = true; + } else if (monomorphicCall == null) { + monomorphicCall = methodDep; + } else { + monomorphicCall.external = true; + monomorphicCall = null; + methodDep.external = true; + isPolymorphic = true; + } DependencyNode[] targetParams = methodDep.getVariables(); if (parameters[0] != null && targetParams[0] != null) { parameters[0].connect(targetParams[0],