Improve optimization of unused methods that were inlined on every usage

This commit is contained in:
Alexey Andreev 2020-02-28 14:42:51 +03:00
parent aefdee2507
commit 2f95045345
2 changed files with 14 additions and 2 deletions

View File

@ -36,7 +36,7 @@ public class ExpressionSideEffectDecomposer extends RecursiveVisitor {
public void visit(ConditionalExpr expr) { public void visit(ConditionalExpr expr) {
ConditionalStatement statement = new ConditionalStatement(); ConditionalStatement statement = new ConditionalStatement();
statement.setCondition(expr.getCondition()); 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())); expr.getAlternative().acceptVisitor(new ExpressionSideEffectDecomposer(statement.getAlternative()));
target.add(statement); target.add(statement);
} }

View File

@ -29,6 +29,8 @@ class VirtualCallConsumer implements DependencyConsumer {
private final BitSet knownTypes = new BitSet(); private final BitSet knownTypes = new BitSet();
private DependencyGraphBuilder.ExceptionConsumer exceptionConsumer; private DependencyGraphBuilder.ExceptionConsumer exceptionConsumer;
private DependencyTypeFilter filter; private DependencyTypeFilter filter;
private boolean isPolymorphic;
private MethodDependency monomorphicCall;
VirtualCallConsumer(DependencyNode node, String filterClass, VirtualCallConsumer(DependencyNode node, String filterClass,
MethodDescriptor methodDesc, DependencyAnalyzer analyzer, DependencyNode[] parameters, MethodDescriptor methodDesc, DependencyAnalyzer analyzer, DependencyNode[] parameters,
@ -67,7 +69,17 @@ class VirtualCallConsumer implements DependencyConsumer {
MethodDependency methodDep = analyzer.linkMethod(className, methodDesc); MethodDependency methodDep = analyzer.linkMethod(className, methodDesc);
methodDep.addLocation(location); methodDep.addLocation(location);
if (!methodDep.isMissing()) { 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(); DependencyNode[] targetParams = methodDep.getVariables();
if (parameters[0] != null && targetParams[0] != null) { if (parameters[0] != null && targetParams[0] != null) {
parameters[0].connect(targetParams[0], parameters[0].connect(targetParams[0],