diff --git a/core/src/main/java/org/teavm/backend/javascript/rendering/Renderer.java b/core/src/main/java/org/teavm/backend/javascript/rendering/Renderer.java index 816d7e2bc..e1c2a5ef2 100644 --- a/core/src/main/java/org/teavm/backend/javascript/rendering/Renderer.java +++ b/core/src/main/java/org/teavm/backend/javascript/rendering/Renderer.java @@ -408,7 +408,8 @@ public class Renderer implements RenderingManager { if (clinit != null && context.isDynamicInitializer(cls.getName())) { renderCallClinit(clinit, cls); } - if (!cls.getClassHolder().getModifiers().contains(ElementModifier.INTERFACE)) { + if (!cls.getClassHolder().hasModifier(ElementModifier.INTERFACE) + && !cls.getClassHolder().hasModifier(ElementModifier.ABSTRACT)) { for (PreparedMethod method : cls.getMethods()) { if (!method.methodHolder.getModifiers().contains(ElementModifier.STATIC)) { if (method.reference.getName().equals("")) { diff --git a/core/src/main/java/org/teavm/model/optimization/DefaultInliningStrategy.java b/core/src/main/java/org/teavm/model/optimization/DefaultInliningStrategy.java index 1e3d7f489..6106a4abb 100644 --- a/core/src/main/java/org/teavm/model/optimization/DefaultInliningStrategy.java +++ b/core/src/main/java/org/teavm/model/optimization/DefaultInliningStrategy.java @@ -124,26 +124,37 @@ public class DefaultInliningStrategy implements InliningStrategy { public void invoke(VariableReader receiver, VariableReader instance, MethodReference method, List arguments, InvocationType type) { if (type == InvocationType.SPECIAL && context != null && context.isUsedOnce(method)) { - callsToUsedOnceMethods = true; + ProgramReader program = context.getProgram(method); + if (!isTrivialCall(program)) { + callsToUsedOnceMethods = true; + } } } + private boolean isTrivialCall(ProgramReader program) { + if (program == null) { + return false; + } + Complexity complexity = getComplexity(program, context); + return complexity.score <= 1 && !complexity.callsToUsedOnceMethods; + } + @Override public void choose(VariableReader condition, List table, BasicBlockReader defaultTarget) { - complexity += 3; + complexity += 2; } @Override public void jumpIf(BranchingCondition cond, VariableReader operand, BasicBlockReader consequent, BasicBlockReader alternative) { - complexity += 2; + complexity += 1; } @Override public void jumpIf(BinaryBranchingCondition cond, VariableReader first, VariableReader second, BasicBlockReader consequent, BasicBlockReader alternative) { - complexity += 2; + complexity += 1; } @Override @@ -155,6 +166,11 @@ public class DefaultInliningStrategy implements InliningStrategy { public void exit(VariableReader valueToReturn) { complexity--; } + + @Override + public void raise(VariableReader exception) { + complexity--; + } } static class Complexity { diff --git a/core/src/main/java/org/teavm/model/optimization/Inlining.java b/core/src/main/java/org/teavm/model/optimization/Inlining.java index 2e5aea3a4..716a81deb 100644 --- a/core/src/main/java/org/teavm/model/optimization/Inlining.java +++ b/core/src/main/java/org/teavm/model/optimization/Inlining.java @@ -500,6 +500,16 @@ public class Inlining { return methodsUsedOnce.contains(method); } + @Override + public ProgramReader getProgram(MethodReference method) { + ClassReader cls = dependencyInfo.getClassSource().get(method.getClassName()); + if (cls == null) { + return null; + } + MethodReader methodReader = cls.getMethod(method.getDescriptor()); + return methodReader != null ? methodReader.getProgram() : null; + } + @Override public int getDepth() { return depth; diff --git a/core/src/main/java/org/teavm/model/optimization/InliningContext.java b/core/src/main/java/org/teavm/model/optimization/InliningContext.java index f0094a20a..e8fa9396e 100644 --- a/core/src/main/java/org/teavm/model/optimization/InliningContext.java +++ b/core/src/main/java/org/teavm/model/optimization/InliningContext.java @@ -16,9 +16,12 @@ package org.teavm.model.optimization; import org.teavm.model.MethodReference; +import org.teavm.model.ProgramReader; public interface InliningContext { boolean isUsedOnce(MethodReference method); + ProgramReader getProgram(MethodReference method); + int getDepth(); } diff --git a/core/src/main/java/org/teavm/vm/TeaVM.java b/core/src/main/java/org/teavm/vm/TeaVM.java index d2eaa0a40..10c885dd6 100644 --- a/core/src/main/java/org/teavm/vm/TeaVM.java +++ b/core/src/main/java/org/teavm/vm/TeaVM.java @@ -837,7 +837,7 @@ public class TeaVM implements TeaVMHost, ServiceRepository { } boolean isVirtual(MethodReference method) { - if (method.getName().equals("") || method.getName().equals("")) { + if (method.getName().equals("")) { return false; } return virtualMethods == null || virtualMethods.contains(method)