From 2bbdf6caba12776c007823047c5082559e80cc12 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Sun, 12 Nov 2017 23:17:51 +0300 Subject: [PATCH] Rename DependencyChecker to DependencyAnalyzer --- .../backend/javascript/JavaScriptTarget.java | 42 +++--- .../org/teavm/backend/wasm/WasmTarget.java | 52 ++++---- .../org/teavm/dependency/ClassDependency.java | 8 +- .../org/teavm/dependency/DependencyAgent.java | 48 +++---- ...cyChecker.java => DependencyAnalyzer.java} | 14 +- ...ava => DependencyAnalyzerInterruptor.java} | 2 +- .../dependency/DependencyGraphBuilder.java | 120 +++++++++--------- .../org/teavm/dependency/DependencyNode.java | 58 ++++----- .../org/teavm/dependency/DependencyType.java | 12 +- .../teavm/dependency/MethodDependency.java | 14 +- core/src/main/java/org/teavm/vm/TeaVM.java | 56 ++++---- .../main/java/org/teavm/vm/TeaVMPhase.java | 2 +- .../main/java/org/teavm/vm/TeaVMTarget.java | 4 +- .../metadata/MetadataGeneratorContext.java | 2 +- .../platform/plugin/AsyncMethodGenerator.java | 14 +- .../plugin/NewInstanceDependencySupport.java | 6 +- .../org/teavm/dependency/DependencyTest.java | 2 +- .../main/java/org/teavm/cli/TeaVMRunner.java | 6 +- .../eclipse/TeaVMEclipseProgressListener.java | 2 +- .../java/org/teavm/idea/jps/TeaVMBuild.java | 2 +- 20 files changed, 233 insertions(+), 233 deletions(-) rename core/src/main/java/org/teavm/dependency/{DependencyChecker.java => DependencyAnalyzer.java} (98%) rename core/src/main/java/org/teavm/dependency/{DependencyCheckerInterruptor.java => DependencyAnalyzerInterruptor.java} (93%) diff --git a/core/src/main/java/org/teavm/backend/javascript/JavaScriptTarget.java b/core/src/main/java/org/teavm/backend/javascript/JavaScriptTarget.java index a552683af..c88590ad8 100644 --- a/core/src/main/java/org/teavm/backend/javascript/JavaScriptTarget.java +++ b/core/src/main/java/org/teavm/backend/javascript/JavaScriptTarget.java @@ -45,7 +45,7 @@ import org.teavm.backend.javascript.spi.Injector; import org.teavm.debugging.information.DebugInformationEmitter; import org.teavm.debugging.information.DummyDebugInformationEmitter; import org.teavm.debugging.information.SourceLocation; -import org.teavm.dependency.DependencyChecker; +import org.teavm.dependency.DependencyAnalyzer; import org.teavm.dependency.DependencyListener; import org.teavm.dependency.MethodDependency; import org.teavm.model.BasicBlock; @@ -168,40 +168,40 @@ public class JavaScriptTarget implements TeaVMTarget, TeaVMJavaScriptHost { } @Override - public void contributeDependencies(DependencyChecker dependencyChecker) { - dependencyChecker.linkMethod(new MethodReference(Class.class.getName(), "getClass", + public void contributeDependencies(DependencyAnalyzer dependencyAnalyzer) { + dependencyAnalyzer.linkMethod(new MethodReference(Class.class.getName(), "getClass", ValueType.object("org.teavm.platform.PlatformClass"), ValueType.parse(Class.class)), null).use(); - dependencyChecker.linkMethod(new MethodReference(String.class, "", char[].class, void.class), + dependencyAnalyzer.linkMethod(new MethodReference(String.class, "", char[].class, void.class), null).use(); - dependencyChecker.linkMethod(new MethodReference(String.class, "getChars", int.class, int.class, char[].class, + dependencyAnalyzer.linkMethod(new MethodReference(String.class, "getChars", int.class, int.class, char[].class, int.class, void.class), null).use(); - MethodDependency internDep = dependencyChecker.linkMethod(new MethodReference(String.class, "intern", + MethodDependency internDep = dependencyAnalyzer.linkMethod(new MethodReference(String.class, "intern", String.class), null); - internDep.getVariable(0).propagate(dependencyChecker.getType("java.lang.String")); + internDep.getVariable(0).propagate(dependencyAnalyzer.getType("java.lang.String")); internDep.use(); - dependencyChecker.linkMethod(new MethodReference(String.class, "length", int.class), null).use(); - dependencyChecker.linkMethod(new MethodReference(Object.class, "clone", Object.class), null).use(); - dependencyChecker.linkMethod(new MethodReference(Thread.class, "currentThread", Thread.class), null).use(); - dependencyChecker.linkMethod(new MethodReference(Thread.class, "getMainThread", Thread.class), null).use(); - dependencyChecker.linkMethod( + dependencyAnalyzer.linkMethod(new MethodReference(String.class, "length", int.class), null).use(); + dependencyAnalyzer.linkMethod(new MethodReference(Object.class, "clone", Object.class), null).use(); + dependencyAnalyzer.linkMethod(new MethodReference(Thread.class, "currentThread", Thread.class), null).use(); + dependencyAnalyzer.linkMethod(new MethodReference(Thread.class, "getMainThread", Thread.class), null).use(); + dependencyAnalyzer.linkMethod( new MethodReference(Thread.class, "setCurrentThread", Thread.class, void.class), null).use(); - MethodDependency exceptionCons = dependencyChecker.linkMethod(new MethodReference( + MethodDependency exceptionCons = dependencyAnalyzer.linkMethod(new MethodReference( NoClassDefFoundError.class, "", String.class, void.class), null); - exceptionCons.getVariable(0).propagate(dependencyChecker.getType(NoClassDefFoundError.class.getName())); - exceptionCons.getVariable(1).propagate(dependencyChecker.getType("java.lang.String")); - exceptionCons = dependencyChecker.linkMethod(new MethodReference(NoSuchFieldError.class, "", + exceptionCons.getVariable(0).propagate(dependencyAnalyzer.getType(NoClassDefFoundError.class.getName())); + exceptionCons.getVariable(1).propagate(dependencyAnalyzer.getType("java.lang.String")); + exceptionCons = dependencyAnalyzer.linkMethod(new MethodReference(NoSuchFieldError.class, "", String.class, void.class), null); exceptionCons.use(); - exceptionCons.getVariable(0).propagate(dependencyChecker.getType(NoSuchFieldError.class.getName())); - exceptionCons.getVariable(1).propagate(dependencyChecker.getType("java.lang.String")); - exceptionCons = dependencyChecker.linkMethod(new MethodReference(NoSuchMethodError.class, "", + exceptionCons.getVariable(0).propagate(dependencyAnalyzer.getType(NoSuchFieldError.class.getName())); + exceptionCons.getVariable(1).propagate(dependencyAnalyzer.getType("java.lang.String")); + exceptionCons = dependencyAnalyzer.linkMethod(new MethodReference(NoSuchMethodError.class, "", String.class, void.class), null); exceptionCons.use(); - exceptionCons.getVariable(0).propagate(dependencyChecker.getType(NoSuchMethodError.class.getName())); - exceptionCons.getVariable(1).propagate(dependencyChecker.getType("java.lang.String")); + exceptionCons.getVariable(0).propagate(dependencyAnalyzer.getType(NoSuchMethodError.class.getName())); + exceptionCons.getVariable(1).propagate(dependencyAnalyzer.getType("java.lang.String")); } @Override diff --git a/core/src/main/java/org/teavm/backend/wasm/WasmTarget.java b/core/src/main/java/org/teavm/backend/wasm/WasmTarget.java index 3b8e90b02..16f559323 100644 --- a/core/src/main/java/org/teavm/backend/wasm/WasmTarget.java +++ b/core/src/main/java/org/teavm/backend/wasm/WasmTarget.java @@ -81,7 +81,7 @@ import org.teavm.backend.wasm.transformation.IndirectCallTraceTransformation; import org.teavm.backend.wasm.transformation.MemoryAccessTraceTransformation; import org.teavm.common.ServiceRepository; import org.teavm.dependency.ClassDependency; -import org.teavm.dependency.DependencyChecker; +import org.teavm.dependency.DependencyAnalyzer; import org.teavm.dependency.DependencyListener; import org.teavm.interop.Address; import org.teavm.interop.DelegateTo; @@ -210,62 +210,62 @@ public class WasmTarget implements TeaVMTarget, TeaVMWasmHost { } @Override - public void contributeDependencies(DependencyChecker dependencyChecker) { + public void contributeDependencies(DependencyAnalyzer dependencyAnalyzer) { for (Class type : Arrays.asList(int.class, long.class, float.class, double.class)) { MethodReference method = new MethodReference(WasmRuntime.class, "compare", type, type, int.class); - dependencyChecker.linkMethod(method, null).use(); + dependencyAnalyzer.linkMethod(method, null).use(); } for (Class type : Arrays.asList(float.class, double.class)) { MethodReference method = new MethodReference(WasmRuntime.class, "remainder", type, type, type); - dependencyChecker.linkMethod(method, null).use(); + dependencyAnalyzer.linkMethod(method, null).use(); } - dependencyChecker.linkMethod(new MethodReference(WasmRuntime.class, "align", Address.class, int.class, + dependencyAnalyzer.linkMethod(new MethodReference(WasmRuntime.class, "align", Address.class, int.class, Address.class), null).use(); - dependencyChecker.linkMethod(new MethodReference(WasmRuntime.class, "fillZero", Address.class, int.class, + dependencyAnalyzer.linkMethod(new MethodReference(WasmRuntime.class, "fillZero", Address.class, int.class, void.class), null).use(); - dependencyChecker.linkMethod(new MethodReference(WasmRuntime.class, "moveMemoryBlock", Address.class, + dependencyAnalyzer.linkMethod(new MethodReference(WasmRuntime.class, "moveMemoryBlock", Address.class, Address.class, int.class, void.class), null).use(); - dependencyChecker.linkMethod(new MethodReference(WasmRuntime.class, "allocStack", + dependencyAnalyzer.linkMethod(new MethodReference(WasmRuntime.class, "allocStack", int.class, Address.class), null).use(); - dependencyChecker.linkMethod(new MethodReference(WasmRuntime.class, "getStackTop", Address.class), + dependencyAnalyzer.linkMethod(new MethodReference(WasmRuntime.class, "getStackTop", Address.class), null) .use(); - dependencyChecker.linkMethod(new MethodReference(WasmRuntime.class, "getNextStackFrame", Address.class, + dependencyAnalyzer.linkMethod(new MethodReference(WasmRuntime.class, "getNextStackFrame", Address.class, Address.class), null).use(); - dependencyChecker.linkMethod(new MethodReference(WasmRuntime.class, "getStackRootCount", Address.class, + dependencyAnalyzer.linkMethod(new MethodReference(WasmRuntime.class, "getStackRootCount", Address.class, int.class), null).use(); - dependencyChecker.linkMethod(new MethodReference(WasmRuntime.class, "getStackRootPointer", Address.class, + dependencyAnalyzer.linkMethod(new MethodReference(WasmRuntime.class, "getStackRootPointer", Address.class, Address.class), null).use(); - dependencyChecker.linkMethod(new MethodReference(WasmRuntime.class, "setExceptionHandlerId", Address.class, + dependencyAnalyzer.linkMethod(new MethodReference(WasmRuntime.class, "setExceptionHandlerId", Address.class, int.class, void.class), null).use(); - dependencyChecker.linkMethod(new MethodReference(WasmRuntime.class, "getCallSiteId", Address.class, + dependencyAnalyzer.linkMethod(new MethodReference(WasmRuntime.class, "getCallSiteId", Address.class, int.class), null).use(); - dependencyChecker.linkMethod(new MethodReference(Allocator.class, "allocate", + dependencyAnalyzer.linkMethod(new MethodReference(Allocator.class, "allocate", RuntimeClass.class, Address.class), null).use(); - dependencyChecker.linkMethod(new MethodReference(Allocator.class, "allocateArray", + dependencyAnalyzer.linkMethod(new MethodReference(Allocator.class, "allocateArray", RuntimeClass.class, int.class, Address.class), null).use(); - dependencyChecker.linkMethod(new MethodReference(Allocator.class, "allocateMultiArray", + dependencyAnalyzer.linkMethod(new MethodReference(Allocator.class, "allocateMultiArray", RuntimeClass.class, Address.class, int.class, RuntimeArray.class), null).use(); - dependencyChecker.linkMethod(new MethodReference(Allocator.class, "", void.class), null).use(); + dependencyAnalyzer.linkMethod(new MethodReference(Allocator.class, "", void.class), null).use(); - dependencyChecker.linkMethod(new MethodReference(ExceptionHandling.class, "throwException", + dependencyAnalyzer.linkMethod(new MethodReference(ExceptionHandling.class, "throwException", Throwable.class, void.class), null).use(); - dependencyChecker.linkMethod(new MethodReference(ExceptionHandling.class, "catchException", + dependencyAnalyzer.linkMethod(new MethodReference(ExceptionHandling.class, "catchException", Throwable.class), null).use(); - dependencyChecker.linkField(new FieldReference("java.lang.Object", "monitor"), null); + dependencyAnalyzer.linkField(new FieldReference("java.lang.Object", "monitor"), null); - ClassDependency runtimeClassDep = dependencyChecker.linkClass(RuntimeClass.class.getName(), null); - ClassDependency runtimeObjectDep = dependencyChecker.linkClass(RuntimeObject.class.getName(), null); - ClassDependency runtimeJavaObjectDep = dependencyChecker.linkClass(RuntimeJavaObject.class.getName(), null); - ClassDependency runtimeArrayDep = dependencyChecker.linkClass(RuntimeArray.class.getName(), null); + ClassDependency runtimeClassDep = dependencyAnalyzer.linkClass(RuntimeClass.class.getName(), null); + ClassDependency runtimeObjectDep = dependencyAnalyzer.linkClass(RuntimeObject.class.getName(), null); + ClassDependency runtimeJavaObjectDep = dependencyAnalyzer.linkClass(RuntimeJavaObject.class.getName(), null); + ClassDependency runtimeArrayDep = dependencyAnalyzer.linkClass(RuntimeArray.class.getName(), null); for (ClassDependency classDep : Arrays.asList(runtimeClassDep, runtimeObjectDep, runtimeJavaObjectDep, runtimeArrayDep)) { for (FieldReader field : classDep.getClassReader().getFields()) { - dependencyChecker.linkField(field.getReference(), null); + dependencyAnalyzer.linkField(field.getReference(), null); } } } diff --git a/core/src/main/java/org/teavm/dependency/ClassDependency.java b/core/src/main/java/org/teavm/dependency/ClassDependency.java index 609eb7cc3..5c0ada184 100644 --- a/core/src/main/java/org/teavm/dependency/ClassDependency.java +++ b/core/src/main/java/org/teavm/dependency/ClassDependency.java @@ -19,12 +19,12 @@ import org.teavm.model.CallLocation; import org.teavm.model.ClassReader; public class ClassDependency implements ClassDependencyInfo { - private DependencyChecker checker; + private DependencyAnalyzer analyzer; private String className; private ClassReader classReader; - ClassDependency(DependencyChecker checker, String className, ClassReader classReader) { - this.checker = checker; + ClassDependency(DependencyAnalyzer analyzer, String className, ClassReader classReader) { + this.analyzer = analyzer; this.className = className; this.classReader = classReader; } @@ -45,7 +45,7 @@ public class ClassDependency implements ClassDependencyInfo { public void initClass(CallLocation callLocation) { if (!isMissing()) { - checker.initClass(this, callLocation); + analyzer.initClass(this, callLocation); } } } diff --git a/core/src/main/java/org/teavm/dependency/DependencyAgent.java b/core/src/main/java/org/teavm/dependency/DependencyAgent.java index a1749b015..b044ec403 100644 --- a/core/src/main/java/org/teavm/dependency/DependencyAgent.java +++ b/core/src/main/java/org/teavm/dependency/DependencyAgent.java @@ -22,104 +22,104 @@ import org.teavm.diagnostics.Diagnostics; import org.teavm.model.*; public class DependencyAgent implements DependencyInfo, ServiceRepository { - private DependencyChecker checker; + private DependencyAnalyzer analyzer; - DependencyAgent(DependencyChecker checker) { - this.checker = checker; + DependencyAgent(DependencyAnalyzer analyzer) { + this.analyzer = analyzer; } public DependencyNode createNode() { - return checker.createNode(); + return analyzer.createNode(); } public DependencyType getType(String name) { - return checker.getType(name); + return analyzer.getType(name); } public String generateClassName() { - return checker.generateClassName(); + return analyzer.generateClassName(); } public String submitClassFile(byte[] data) { - return checker.submitClassFile(data); + return analyzer.submitClassFile(data); } public void submitClass(ClassHolder cls) { - checker.submitClass(cls); + analyzer.submitClass(cls); } public void submitMethod(MethodReference method, Program program) { - checker.submitMethod(method, program); + analyzer.submitMethod(method, program); } public MethodDependency linkMethod(MethodReference methodRef, CallLocation callLocation) { - return checker.linkMethod(methodRef, callLocation); + return analyzer.linkMethod(methodRef, callLocation); } public ClassDependency linkClass(String className, CallLocation callLocation) { - return checker.linkClass(className, callLocation); + return analyzer.linkClass(className, callLocation); } public FieldDependency linkField(FieldReference fieldRef, CallLocation callLocation) { - return checker.linkField(fieldRef, callLocation); + return analyzer.linkField(fieldRef, callLocation); } public Diagnostics getDiagnostics() { - return checker.getDiagnostics(); + return analyzer.getDiagnostics(); } @Override public T getService(Class type) { - return checker.getService(type); + return analyzer.getService(type); } @Override public ClassReaderSource getClassSource() { - return checker.getClassSource(); + return analyzer.getClassSource(); } @Override public ClassLoader getClassLoader() { - return checker.getClassLoader(); + return analyzer.getClassLoader(); } @Override public Collection getReachableMethods() { - return checker.getReachableMethods(); + return analyzer.getReachableMethods(); } @Override public Collection getReachableFields() { - return checker.getReachableFields(); + return analyzer.getReachableFields(); } @Override public Collection getReachableClasses() { - return checker.getReachableClasses(); + return analyzer.getReachableClasses(); } @Override public FieldDependencyInfo getField(FieldReference fieldRef) { - return checker.getField(fieldRef); + return analyzer.getField(fieldRef); } @Override public MethodDependencyInfo getMethod(MethodReference methodRef) { - return checker.getMethod(methodRef); + return analyzer.getMethod(methodRef); } @Override public MethodDependencyInfo getMethodImplementation(MethodReference methodRef) { - return checker.getMethodImplementation(methodRef); + return analyzer.getMethodImplementation(methodRef); } @Override public ClassDependencyInfo getClass(String className) { - return checker.getClass(className); + return analyzer.getClass(className); } @Override public CallGraph getCallGraph() { - return checker.getCallGraph(); + return analyzer.getCallGraph(); } } diff --git a/core/src/main/java/org/teavm/dependency/DependencyChecker.java b/core/src/main/java/org/teavm/dependency/DependencyAnalyzer.java similarity index 98% rename from core/src/main/java/org/teavm/dependency/DependencyChecker.java rename to core/src/main/java/org/teavm/dependency/DependencyAnalyzer.java index ae6574493..07504e634 100644 --- a/core/src/main/java/org/teavm/dependency/DependencyChecker.java +++ b/core/src/main/java/org/teavm/dependency/DependencyAnalyzer.java @@ -57,7 +57,7 @@ import org.teavm.model.util.ModelUtils; import org.teavm.model.util.ProgramUtils; import org.teavm.parsing.Parser; -public class DependencyChecker implements DependencyInfo { +public class DependencyAnalyzer implements DependencyInfo { private static final int PROPAGATION_STACK_THRESHOLD = 50; static final boolean shouldLog = System.getProperty("org.teavm.logDependencies", "false").equals("true"); static final boolean shouldTag = System.getProperty("org.teavm.tagDependencies", "false").equals("true") @@ -77,7 +77,7 @@ public class DependencyChecker implements DependencyInfo { private Queue deferredTasks = new ArrayDeque<>(); List types = new ArrayList<>(); private Map typeMap = new HashMap<>(); - private DependencyCheckerInterruptor interruptor; + private DependencyAnalyzerInterruptor interruptor; private boolean interrupted; private Diagnostics diagnostics; DefaultCallGraph callGraph = new DefaultCallGraph(); @@ -86,7 +86,7 @@ public class DependencyChecker implements DependencyInfo { private boolean completing; private Map superClassFilters = new HashMap<>(); - public DependencyChecker(ClassReaderSource classSource, ClassLoader classLoader, ServiceRepository services, + public DependencyAnalyzer(ClassReaderSource classSource, ClassLoader classLoader, ServiceRepository services, Diagnostics diagnostics) { this.diagnostics = diagnostics; this.classSource = new DependencyClassSource(classSource, diagnostics); @@ -118,11 +118,11 @@ public class DependencyChecker implements DependencyInfo { return agent; } - public DependencyCheckerInterruptor getInterruptor() { + public DependencyAnalyzerInterruptor getInterruptor() { return interruptor; } - public void setInterruptor(DependencyCheckerInterruptor interruptor) { + public void setInterruptor(DependencyAnalyzerInterruptor interruptor) { this.interruptor = interruptor; } @@ -212,7 +212,7 @@ public class DependencyChecker implements DependencyInfo { dep.used = false; lock(dep, false); deferredTasks.add(() -> { - DependencyGraphBuilder graphBuilder = new DependencyGraphBuilder(DependencyChecker.this); + DependencyGraphBuilder graphBuilder = new DependencyGraphBuilder(DependencyAnalyzer.this); graphBuilder.buildGraph(dep); dep.used = true; }); @@ -448,7 +448,7 @@ public class DependencyChecker implements DependencyInfo { void scheduleMethodAnalysis(MethodDependency dep) { deferredTasks.add(() -> { - DependencyGraphBuilder graphBuilder = new DependencyGraphBuilder(DependencyChecker.this); + DependencyGraphBuilder graphBuilder = new DependencyGraphBuilder(DependencyAnalyzer.this); graphBuilder.buildGraph(dep); }); } diff --git a/core/src/main/java/org/teavm/dependency/DependencyCheckerInterruptor.java b/core/src/main/java/org/teavm/dependency/DependencyAnalyzerInterruptor.java similarity index 93% rename from core/src/main/java/org/teavm/dependency/DependencyCheckerInterruptor.java rename to core/src/main/java/org/teavm/dependency/DependencyAnalyzerInterruptor.java index 49ebb213f..a8815e480 100644 --- a/core/src/main/java/org/teavm/dependency/DependencyCheckerInterruptor.java +++ b/core/src/main/java/org/teavm/dependency/DependencyAnalyzerInterruptor.java @@ -15,6 +15,6 @@ */ package org.teavm.dependency; -public interface DependencyCheckerInterruptor { +public interface DependencyAnalyzerInterruptor { boolean shouldContinue(); } diff --git a/core/src/main/java/org/teavm/dependency/DependencyGraphBuilder.java b/core/src/main/java/org/teavm/dependency/DependencyGraphBuilder.java index 64da6fcc3..ad16d503a 100644 --- a/core/src/main/java/org/teavm/dependency/DependencyGraphBuilder.java +++ b/core/src/main/java/org/teavm/dependency/DependencyGraphBuilder.java @@ -58,7 +58,7 @@ import org.teavm.model.instructions.NullConstantInstruction; import org.teavm.model.text.ListingBuilder; class DependencyGraphBuilder { - private DependencyChecker dependencyChecker; + private DependencyAnalyzer dependencyAnalyzer; private DependencyNode[] nodes; private DependencyNode resultNode; private Program program; @@ -66,12 +66,12 @@ class DependencyGraphBuilder { private TextLocation currentLocation; private ExceptionConsumer currentExceptionConsumer; - DependencyGraphBuilder(DependencyChecker dependencyChecker) { - this.dependencyChecker = dependencyChecker; + DependencyGraphBuilder(DependencyAnalyzer dependencyAnalyzer) { + this.dependencyAnalyzer = dependencyAnalyzer; } public void buildGraph(MethodDependency dep) { - caller = dependencyChecker.callGraph.getNode(dep.getReference()); + caller = dependencyAnalyzer.callGraph.getNode(dep.getReference()); MethodHolder method = dep.method; if (method.getProgram() == null || method.getProgram().basicBlockCount() == 0) { return; @@ -93,7 +93,7 @@ class DependencyGraphBuilder { int[] nodeMapping = dfgBuilder.buildMapping(program, significantParams, !(method.getResultType() instanceof ValueType.Primitive) && method.getResultType() != ValueType.VOID); - if (DependencyChecker.shouldLog) { + if (DependencyAnalyzer.shouldLog) { System.out.println("Method reached: " + method.getReference()); System.out.print(new ListingBuilder().buildListing(program, " ")); for (int i = 0; i < nodeMapping.length; ++i) { @@ -110,9 +110,9 @@ class DependencyGraphBuilder { DependencyNode[] nodeClasses = Arrays.copyOf(dep.getVariables(), nodeClassCount); MethodReference ref = method.getReference(); for (int i = dep.getVariableCount(); i < nodeClasses.length; ++i) { - nodeClasses[i] = dependencyChecker.createNode(); + nodeClasses[i] = dependencyAnalyzer.createNode(); nodeClasses[i].method = ref; - if (DependencyChecker.shouldTag) { + if (DependencyAnalyzer.shouldTag) { nodeClasses[i].setTag(dep.getMethod().getReference() + ":" + i); } } @@ -140,7 +140,7 @@ class DependencyGraphBuilder { for (TryCatchBlockReader tryCatch : block.readTryCatchBlocks()) { if (tryCatch.getExceptionType() != null) { - dependencyChecker.linkClass(tryCatch.getExceptionType(), new CallLocation(caller.getMethod())); + dependencyAnalyzer.linkClass(tryCatch.getExceptionType(), new CallLocation(caller.getMethod())); } } } @@ -148,29 +148,29 @@ class DependencyGraphBuilder { if (method.hasModifier(ElementModifier.SYNCHRONIZED)) { List syncNodes = new ArrayList<>(); - MethodDependency methodDep = dependencyChecker.linkMethod( + MethodDependency methodDep = dependencyAnalyzer.linkMethod( new MethodReference(Object.class, "monitorEnter", Object.class, void.class), null); syncNodes.add(methodDep.getVariable(1)); methodDep.use(); - methodDep = dependencyChecker.linkMethod( + methodDep = dependencyAnalyzer.linkMethod( new MethodReference(Object.class, "monitorEnterSync", Object.class, void.class), null); syncNodes.add(methodDep.getVariable(1)); methodDep.use(); - methodDep = dependencyChecker.linkMethod( + methodDep = dependencyAnalyzer.linkMethod( new MethodReference(Object.class, "monitorExit", Object.class, void.class), null); syncNodes.add(methodDep.getVariable(1)); methodDep.use(); - methodDep = dependencyChecker.linkMethod( + methodDep = dependencyAnalyzer.linkMethod( new MethodReference(Object.class, "monitorExitSync", Object.class, void.class), null); syncNodes.add(methodDep.getVariable(1)); methodDep.use(); if (method.hasModifier(ElementModifier.STATIC)) { for (DependencyNode node : syncNodes) { - node.propagate(dependencyChecker.getType("java.lang.Class")); + node.propagate(dependencyAnalyzer.getType("java.lang.Class")); } } else { for (DependencyNode node : syncNodes) { @@ -184,7 +184,7 @@ class DependencyGraphBuilder { if (program == null) { return; } - ProgramEmitter pe = ProgramEmitter.create(program, dependencyChecker.getClassSource()); + ProgramEmitter pe = ProgramEmitter.create(program, dependencyAnalyzer.getClassSource()); boolean hasIndy = false; for (int i = 0; i < program.basicBlockCount(); ++i) { BasicBlock block = program.basicBlockAt(i); @@ -197,7 +197,7 @@ class DependencyGraphBuilder { InvokeDynamicInstruction indy = (InvokeDynamicInstruction) insn; MethodReference bootstrapMethod = new MethodReference(indy.getBootstrapMethod().getClassName(), indy.getBootstrapMethod().getName(), indy.getBootstrapMethod().signature()); - BootstrapMethodSubstitutor substitutor = dependencyChecker.bootstrapMethodSubstitutors + BootstrapMethodSubstitutor substitutor = dependencyAnalyzer.bootstrapMethodSubstitutors .get(bootstrapMethod); if (substitutor == null) { NullConstantInstruction nullInsn = new NullConstantInstruction(); @@ -205,7 +205,7 @@ class DependencyGraphBuilder { nullInsn.setLocation(indy.getLocation()); insn.replace(nullInsn); CallLocation location = new CallLocation(caller.getMethod(), currentLocation); - dependencyChecker.getDiagnostics().error(location, "Substitutor for bootstrap " + dependencyAnalyzer.getDiagnostics().error(location, "Substitutor for bootstrap " + "method {{m0}} was not found", bootstrapMethod); continue; } @@ -241,7 +241,7 @@ class DependencyGraphBuilder { indy.getInstance() != null ? pe.var(indy.getInstance(), ValueType.object(methodDep.getMethod().getOwnerName())) : null, arguments, indy.getBootstrapMethod(), indy.getBootstrapArguments(), - dependencyChecker.getAgent()); + dependencyAnalyzer.getAgent()); ValueEmitter result = substitutor.substitute(callSite, pe); if (result.getVariable() != null && result.getVariable() != indy.getReceiver()) { AssignInstruction assign = new AssignInstruction(); @@ -265,24 +265,24 @@ class DependencyGraphBuilder { for (int i = 0; i < tryCatchBlocks.size(); ++i) { TryCatchBlockReader tryCatch = tryCatchBlocks.get(i); if (tryCatch.getExceptionType() != null) { - exceptions[i] = dependencyChecker.getClassSource().get(tryCatch.getExceptionType()); + exceptions[i] = dependencyAnalyzer.getClassSource().get(tryCatch.getExceptionType()); } if (tryCatch.getHandler().getExceptionVariable() != null) { vars[i] = methodDep.getVariable(tryCatch.getHandler().getExceptionVariable().getIndex()); } } - return new ExceptionConsumer(dependencyChecker, exceptions, vars, methodDep); + return new ExceptionConsumer(dependencyAnalyzer, exceptions, vars, methodDep); } static class ExceptionConsumer implements DependencyConsumer { - private DependencyChecker checker; + private DependencyAnalyzer analyzer; private ClassReader[] exceptions; private DependencyNode[] vars; private MethodDependency method; - ExceptionConsumer(DependencyChecker checker, ClassReader[] exceptions, DependencyNode[] vars, + ExceptionConsumer(DependencyAnalyzer analyzer, ClassReader[] exceptions, DependencyNode[] vars, MethodDependency method) { - this.checker = checker; + this.analyzer = analyzer; this.exceptions = exceptions; this.vars = vars; this.method = method; @@ -290,7 +290,7 @@ class DependencyGraphBuilder { @Override public void consume(DependencyType type) { - ClassReaderSource classSource = checker.getClassSource(); + ClassReaderSource classSource = analyzer.getClassSource(); for (int i = 0; i < exceptions.length; ++i) { if (exceptions[i] == null || classSource.isSuperType(exceptions[i].getName(), type.getName()) .orElse(false)) { @@ -307,7 +307,7 @@ class DependencyGraphBuilder { static class VirtualCallConsumer implements DependencyConsumer { private final DependencyNode node; private final MethodDescriptor methodDesc; - private final DependencyChecker checker; + private final DependencyAnalyzer analyzer; private final DependencyNode[] parameters; private final DependencyNode result; private final DefaultCallGraphNode caller; @@ -318,13 +318,13 @@ class DependencyGraphBuilder { private SuperClassFilter filter; VirtualCallConsumer(DependencyNode node, String filterClass, - MethodDescriptor methodDesc, DependencyChecker checker, DependencyNode[] parameters, + MethodDescriptor methodDesc, DependencyAnalyzer analyzer, DependencyNode[] parameters, DependencyNode result, DefaultCallGraphNode caller, TextLocation location, ExceptionConsumer exceptionConsumer) { this.node = node; - this.filter = checker.getSuperClassFilter(filterClass); + this.filter = analyzer.getSuperClassFilter(filterClass); this.methodDesc = methodDesc; - this.checker = checker; + this.analyzer = analyzer; this.parameters = parameters; this.result = result; this.caller = caller; @@ -340,26 +340,26 @@ class DependencyGraphBuilder { knownTypes.set(type.index); String className = type.getName(); - if (DependencyChecker.shouldLog) { + if (DependencyAnalyzer.shouldLog) { System.out.println("Virtual call of " + methodDesc + " detected on " + node.getTag() + ". " + "Target class is " + className); } if (className.startsWith("[")) { className = "java.lang.Object"; - type = checker.getType(className); + type = analyzer.getType(className); } if (!filter.match(type)) { return; } MethodReference methodRef = new MethodReference(className, methodDesc); - MethodDependency methodDep = checker.linkMethod(methodRef, new CallLocation(caller.getMethod(), location)); + MethodDependency methodDep = analyzer.linkMethod(methodRef, new CallLocation(caller.getMethod(), location)); if (!methodDep.isMissing() && knownMethods.add(methodRef)) { methodDep.use(); DependencyNode[] targetParams = methodDep.getVariables(); if (parameters[0] != null && targetParams[0] != null) { parameters[0].connect(targetParams[0], - checker.getSuperClassFilter(methodDep.getMethod().getOwnerName())); + analyzer.getSuperClassFilter(methodDep.getMethod().getOwnerName())); } for (int i = 1; i < parameters.length; ++i) { if (parameters[i] != null && targetParams[i] != null) { @@ -384,7 +384,7 @@ class DependencyGraphBuilder { public void classConstant(VariableReader receiver, ValueType cst) { DependencyNode node = nodes[receiver.getIndex()]; if (node != null) { - node.propagate(dependencyChecker.getType("java.lang.Class")); + node.propagate(dependencyAnalyzer.getType("java.lang.Class")); if (!(cst instanceof ValueType.Primitive)) { StringBuilder sb = new StringBuilder(); while (cst instanceof ValueType.Array) { @@ -396,7 +396,7 @@ class DependencyGraphBuilder { } else { sb.append(cst.toString()); } - node.getClassValueNode().propagate(dependencyChecker.getType(sb.toString())); + node.getClassValueNode().propagate(dependencyAnalyzer.getType(sb.toString())); } } while (cst instanceof ValueType.Array) { @@ -404,7 +404,7 @@ class DependencyGraphBuilder { } if (cst instanceof ValueType.Object) { final String className = ((ValueType.Object) cst).getClassName(); - dependencyChecker.linkClass(className, new CallLocation(caller.getMethod(), currentLocation)); + dependencyAnalyzer.linkClass(className, new CallLocation(caller.getMethod(), currentLocation)); } } @@ -412,9 +412,9 @@ class DependencyGraphBuilder { public void stringConstant(VariableReader receiver, String cst) { DependencyNode node = nodes[receiver.getIndex()]; if (node != null) { - node.propagate(dependencyChecker.getType("java.lang.String")); + node.propagate(dependencyAnalyzer.getType("java.lang.String")); } - MethodDependency method = dependencyChecker.linkMethod(new MethodReference(String.class, + MethodDependency method = dependencyAnalyzer.linkMethod(new MethodReference(String.class, "", char[].class, void.class), new CallLocation(caller.getMethod(), currentLocation)); method.use(); } @@ -432,13 +432,13 @@ class DependencyGraphBuilder { public void cast(VariableReader receiver, VariableReader value, ValueType targetType) { DependencyNode valueNode = nodes[value.getIndex()]; DependencyNode receiverNode = nodes[receiver.getIndex()]; - ClassReaderSource classSource = dependencyChecker.getClassSource(); + ClassReaderSource classSource = dependencyAnalyzer.getClassSource(); if (targetType instanceof ValueType.Object) { String targetClsName = ((ValueType.Object) targetType).getClassName(); final ClassReader targetClass = classSource.get(targetClsName); if (targetClass != null && !(targetClass.getName().equals("java.lang.Object"))) { if (valueNode != null && receiverNode != null) { - valueNode.connect(receiverNode, dependencyChecker.getSuperClassFilter(targetClass.getName())); + valueNode.connect(receiverNode, dependencyAnalyzer.getSuperClassFilter(targetClass.getName())); } return; } @@ -466,11 +466,11 @@ class DependencyGraphBuilder { public void createArray(VariableReader receiver, ValueType itemType, VariableReader size) { DependencyNode node = nodes[receiver.getIndex()]; if (node != null) { - node.propagate(dependencyChecker.getType("[" + itemType)); + node.propagate(dependencyAnalyzer.getType("[" + itemType)); } String className = extractClassName(itemType); if (className != null) { - dependencyChecker.linkClass(className, new CallLocation(caller.getMethod(), currentLocation)); + dependencyAnalyzer.linkClass(className, new CallLocation(caller.getMethod(), currentLocation)); } } @@ -501,28 +501,28 @@ class DependencyGraphBuilder { if (node == null) { break; } - node.propagate(dependencyChecker.getType(sb.substring(i, sb.length()))); + node.propagate(dependencyAnalyzer.getType(sb.substring(i, sb.length()))); node = node.getArrayItem(); } String className = extractClassName(itemType); if (className != null) { - dependencyChecker.linkClass(className, new CallLocation(caller.getMethod(), currentLocation)); + dependencyAnalyzer.linkClass(className, new CallLocation(caller.getMethod(), currentLocation)); } } @Override public void create(VariableReader receiver, String type) { - dependencyChecker.linkClass(type, new CallLocation(caller.getMethod(), currentLocation)); + dependencyAnalyzer.linkClass(type, new CallLocation(caller.getMethod(), currentLocation)); DependencyNode node = nodes[receiver.getIndex()]; if (node != null) { - node.propagate(dependencyChecker.getType(type)); + node.propagate(dependencyAnalyzer.getType(type)); } } @Override public void getField(VariableReader receiver, VariableReader instance, FieldReference field, ValueType fieldType) { - FieldDependency fieldDep = dependencyChecker.linkField(field, + FieldDependency fieldDep = dependencyAnalyzer.linkField(field, new CallLocation(caller.getMethod(), currentLocation)); if (!(fieldType instanceof ValueType.Primitive)) { DependencyNode receiverNode = nodes[receiver.getIndex()]; @@ -536,7 +536,7 @@ class DependencyGraphBuilder { @Override public void putField(VariableReader instance, FieldReference field, VariableReader value, ValueType fieldType) { - FieldDependency fieldDep = dependencyChecker.linkField(field, + FieldDependency fieldDep = dependencyAnalyzer.linkField(field, new CallLocation(caller.getMethod(), currentLocation)); if (!(fieldType instanceof ValueType.Primitive)) { DependencyNode valueNode = nodes[value.getIndex()]; @@ -555,7 +555,7 @@ class DependencyGraphBuilder { arrayNode.addConsumer(receiverNode::propagate); arrayNode.getArrayItem().connect(receiverNode.getArrayItem()); } - MethodDependency cloneDep = dependencyChecker.linkMethod( + MethodDependency cloneDep = dependencyAnalyzer.linkMethod( new MethodReference(Object.class, "clone", Object.class), new CallLocation(caller.getMethod(), currentLocation)); arrayNode.connect(cloneDep.getVariable(0)); @@ -615,8 +615,8 @@ class DependencyGraphBuilder { private void invokeSpecial(VariableReader receiver, VariableReader instance, MethodReference method, List arguments) { CallLocation callLocation = new CallLocation(caller.getMethod(), currentLocation); - dependencyChecker.linkClass(method.getClassName(), callLocation).initClass(callLocation); - MethodDependency methodDep = dependencyChecker.linkMethod(method, callLocation); + dependencyAnalyzer.linkClass(method.getClassName(), callLocation).initClass(callLocation); + MethodDependency methodDep = dependencyAnalyzer.linkMethod(method, callLocation); methodDep.use(); if (methodDep.isMissing()) { return; @@ -650,14 +650,14 @@ class DependencyGraphBuilder { } actualArgs[0] = nodes[instance.getIndex()]; DependencyConsumer listener = new VirtualCallConsumer(nodes[instance.getIndex()], - method.getClassName(), method.getDescriptor(), dependencyChecker, actualArgs, + method.getClassName(), method.getDescriptor(), dependencyAnalyzer, actualArgs, receiver != null ? nodes[receiver.getIndex()] : null, caller, currentLocation, currentExceptionConsumer); nodes[instance.getIndex()].addConsumer(listener); - dependencyChecker.getClassSource().overriddenMethods(method).forEach(methodImpl -> { + dependencyAnalyzer.getClassSource().overriddenMethods(method).forEach(methodImpl -> { CallLocation callLocation = new CallLocation(caller.getMethod(), currentLocation); - dependencyChecker.linkMethod(methodImpl.getReference(), callLocation); + dependencyAnalyzer.linkMethod(methodImpl.getReference(), callLocation); }); } @@ -665,7 +665,7 @@ class DependencyGraphBuilder { public void isInstance(VariableReader receiver, VariableReader value, final ValueType type) { String className = extractClassName(type); if (className != null) { - dependencyChecker.linkClass(className, new CallLocation(caller.getMethod(), currentLocation)); + dependencyAnalyzer.linkClass(className, new CallLocation(caller.getMethod(), currentLocation)); } } @@ -679,7 +679,7 @@ class DependencyGraphBuilder { @Override public void initClass(final String className) { CallLocation callLocation = new CallLocation(caller.getMethod(), currentLocation); - dependencyChecker.linkClass(className, callLocation).initClass(callLocation); + dependencyAnalyzer.linkClass(className, callLocation).initClass(callLocation); } @Override @@ -687,19 +687,19 @@ class DependencyGraphBuilder { DependencyNode valueNode = nodes[value.getIndex()]; DependencyNode receiverNode = nodes[receiver.getIndex()]; valueNode.connect(receiverNode); - dependencyChecker.linkMethod(new MethodReference(NullPointerException.class, "", void.class), + dependencyAnalyzer.linkMethod(new MethodReference(NullPointerException.class, "", void.class), new CallLocation(caller.getMethod(), currentLocation)).use(); - currentExceptionConsumer.consume(dependencyChecker.getType("java.lang.NullPointerException")); + currentExceptionConsumer.consume(dependencyAnalyzer.getType("java.lang.NullPointerException")); } @Override public void monitorEnter(VariableReader objectRef) { - MethodDependency methodDep = dependencyChecker.linkMethod( + MethodDependency methodDep = dependencyAnalyzer.linkMethod( new MethodReference(Object.class, "monitorEnter", Object.class, void.class), null); nodes[objectRef.getIndex()].connect(methodDep.getVariable(1)); methodDep.use(); - methodDep = dependencyChecker.linkMethod( + methodDep = dependencyAnalyzer.linkMethod( new MethodReference(Object.class, "monitorEnterSync", Object.class, void.class), null); nodes[objectRef.getIndex()].connect(methodDep.getVariable(1)); methodDep.use(); @@ -707,12 +707,12 @@ class DependencyGraphBuilder { @Override public void monitorExit(VariableReader objectRef) { - MethodDependency methodDep = dependencyChecker.linkMethod( + MethodDependency methodDep = dependencyAnalyzer.linkMethod( new MethodReference(Object.class, "monitorExit", Object.class, void.class), null); nodes[objectRef.getIndex()].connect(methodDep.getVariable(1)); methodDep.use(); - methodDep = dependencyChecker.linkMethod( + methodDep = dependencyAnalyzer.linkMethod( new MethodReference(Object.class, "monitorExitSync", Object.class, void.class), null); nodes[objectRef.getIndex()].connect(methodDep.getVariable(1)); methodDep.use(); diff --git a/core/src/main/java/org/teavm/dependency/DependencyNode.java b/core/src/main/java/org/teavm/dependency/DependencyNode.java index 4f7c45e8e..b478ea7c2 100644 --- a/core/src/main/java/org/teavm/dependency/DependencyNode.java +++ b/core/src/main/java/org/teavm/dependency/DependencyNode.java @@ -21,7 +21,7 @@ import org.teavm.model.ValueType; public class DependencyNode implements ValueDependencyInfo { private static final int SMALL_TYPES_THRESHOLD = 6; - private DependencyChecker dependencyChecker; + private DependencyAnalyzer dependencyAnalyzer; private List followers; private int[] smallTypes; private BitSet types; @@ -35,12 +35,12 @@ public class DependencyNode implements ValueDependencyInfo { private ValueType typeFilter; private SuperClassFilter cachedTypeFilter; - DependencyNode(DependencyChecker dependencyChecker, ValueType typeFilter) { - this(dependencyChecker, typeFilter, 0); + DependencyNode(DependencyAnalyzer dependencyAnalyzer, ValueType typeFilter) { + this(dependencyAnalyzer, typeFilter, 0); } - private DependencyNode(DependencyChecker dependencyChecker, ValueType typeFilter, int degree) { - this.dependencyChecker = dependencyChecker; + private DependencyNode(DependencyAnalyzer dependencyAnalyzer, ValueType typeFilter, int degree) { + this.dependencyAnalyzer = dependencyAnalyzer; this.degree = degree; this.typeFilter = typeFilter; } @@ -63,7 +63,7 @@ public class DependencyNode implements ValueDependencyInfo { } } if (smallTypes.length == SMALL_TYPES_THRESHOLD) { - types = new BitSet(dependencyChecker.types.size() * 2); + types = new BitSet(dependencyAnalyzer.types.size() * 2); for (int existingType : smallTypes) { types.set(existingType); } @@ -93,7 +93,7 @@ public class DependencyNode implements ValueDependencyInfo { return; } if (addType(type) && filter(type)) { - if (DependencyChecker.shouldLog) { + if (DependencyAnalyzer.shouldLog) { System.out.println(tag + " -> " + type.getName()); } scheduleSingleType(type); @@ -103,13 +103,13 @@ public class DependencyNode implements ValueDependencyInfo { private void scheduleSingleType(DependencyType type) { if (followers != null) { for (DependencyConsumer consumer : followers.toArray(new DependencyConsumer[followers.size()])) { - dependencyChecker.schedulePropagation(consumer, type); + dependencyAnalyzer.schedulePropagation(consumer, type); } } if (transitions != null) { for (DependencyNodeToNodeTransition consumer : transitions.toArray( new DependencyNodeToNodeTransition[transitions.size()])) { - dependencyChecker.schedulePropagation(consumer, type); + dependencyAnalyzer.schedulePropagation(consumer, type); } } } @@ -129,7 +129,7 @@ public class DependencyNode implements ValueDependencyInfo { if (j == 0) { return; } - if (DependencyChecker.shouldLog) { + if (DependencyAnalyzer.shouldLog) { for (int i = 0; i < j; ++i) { System.out.println(tag + " -> " + newTypes[i].getName()); } @@ -147,13 +147,13 @@ public class DependencyNode implements ValueDependencyInfo { } if (followers != null) { for (DependencyConsumer consumer : followers.toArray(new DependencyConsumer[followers.size()])) { - dependencyChecker.schedulePropagation(consumer, newTypes); + dependencyAnalyzer.schedulePropagation(consumer, newTypes); } } if (transitions != null) { for (DependencyNodeToNodeTransition consumer : transitions.toArray( new DependencyNodeToNodeTransition[transitions.size()])) { - dependencyChecker.schedulePropagation(consumer, newTypes); + dependencyAnalyzer.schedulePropagation(consumer, newTypes); } } } @@ -170,7 +170,7 @@ public class DependencyNode implements ValueDependencyInfo { } else { superClass = "java.lang.Object"; } - cachedTypeFilter = dependencyChecker.getSuperClassFilter(superClass); + cachedTypeFilter = dependencyAnalyzer.getSuperClassFilter(superClass); } return cachedTypeFilter.match(type); @@ -208,7 +208,7 @@ public class DependencyNode implements ValueDependencyInfo { } transitions.add(transition); - if (DependencyChecker.shouldLog) { + if (DependencyAnalyzer.shouldLog) { System.out.println("Connecting " + tag + " to " + node.tag); } @@ -220,17 +220,17 @@ public class DependencyNode implements ValueDependencyInfo { DependencyType[] types = new DependencyType[this.types.cardinality()]; int j = 0; for (int index = this.types.nextSetBit(0); index >= 0; index = this.types.nextSetBit(index + 1)) { - DependencyType type = dependencyChecker.types.get(index); + DependencyType type = dependencyAnalyzer.types.get(index); types[j++] = type; } - dependencyChecker.schedulePropagation(transition, types); + dependencyAnalyzer.schedulePropagation(transition, types); } else if (this.smallTypes != null) { DependencyType[] types = new DependencyType[smallTypes.length]; for (int i = 0; i < types.length; ++i) { - DependencyType type = dependencyChecker.types.get(smallTypes[i]); + DependencyType type = dependencyAnalyzer.types.get(smallTypes[i]); types[i] = type; } - dependencyChecker.schedulePropagation(transition, types); + dependencyAnalyzer.schedulePropagation(transition, types); } } @@ -239,17 +239,17 @@ public class DependencyNode implements ValueDependencyInfo { DependencyType[] types = new DependencyType[this.types.cardinality()]; int j = 0; for (int index = this.types.nextSetBit(0); index >= 0; index = this.types.nextSetBit(index + 1)) { - DependencyType type = dependencyChecker.types.get(index); + DependencyType type = dependencyAnalyzer.types.get(index); types[j++] = type; } - dependencyChecker.schedulePropagation(transition, types); + dependencyAnalyzer.schedulePropagation(transition, types); } else if (this.smallTypes != null) { DependencyType[] types = new DependencyType[smallTypes.length]; for (int i = 0; i < types.length; ++i) { - DependencyType type = dependencyChecker.types.get(smallTypes[i]); + DependencyType type = dependencyAnalyzer.types.get(smallTypes[i]); types[i] = type; } - dependencyChecker.schedulePropagation(transition, types); + dependencyAnalyzer.schedulePropagation(transition, types); } } @@ -263,8 +263,8 @@ public class DependencyNode implements ValueDependencyInfo { ValueType itemTypeFilter = typeFilter instanceof ValueType.Array ? ((ValueType.Array) typeFilter).getItemType() : null; - arrayItemNode = new DependencyNode(dependencyChecker, itemTypeFilter, degree + 1); - if (DependencyChecker.shouldTag) { + arrayItemNode = new DependencyNode(dependencyAnalyzer, itemTypeFilter, degree + 1); + if (DependencyAnalyzer.shouldTag) { arrayItemNode.tag = tag + "["; } } @@ -274,9 +274,9 @@ public class DependencyNode implements ValueDependencyInfo { @Override public DependencyNode getClassValueNode() { if (classValueNode == null) { - classValueNode = new DependencyNode(dependencyChecker, null, degree); + classValueNode = new DependencyNode(dependencyAnalyzer, null, degree); classValueNode.classValueNode = classValueNode; - if (DependencyChecker.shouldTag) { + if (DependencyAnalyzer.shouldTag) { classValueNode.tag = tag + "@"; } } @@ -302,7 +302,7 @@ public class DependencyNode implements ValueDependencyInfo { @Override public boolean hasType(String type) { - return hasType(dependencyChecker.getType(type)); + return hasType(dependencyAnalyzer.getType(type)); } @Override @@ -311,7 +311,7 @@ public class DependencyNode implements ValueDependencyInfo { String[] result = new String[smallTypes.length]; int j = 0; for (int i = 0; i < result.length; ++i) { - DependencyType type = dependencyChecker.types.get(smallTypes[i]); + DependencyType type = dependencyAnalyzer.types.get(smallTypes[i]); if (filter(type)) { result[j++] = type.getName(); } @@ -327,7 +327,7 @@ public class DependencyNode implements ValueDependencyInfo { String[] result = new String[types.cardinality()]; int j = 0; for (int index = types.nextSetBit(0); index >= 0; index = types.nextSetBit(index + 1)) { - DependencyType type = dependencyChecker.types.get(index); + DependencyType type = dependencyAnalyzer.types.get(index); if (filter(type)) { result[j++] = type.getName(); } diff --git a/core/src/main/java/org/teavm/dependency/DependencyType.java b/core/src/main/java/org/teavm/dependency/DependencyType.java index d0a3bf8a2..56281283f 100644 --- a/core/src/main/java/org/teavm/dependency/DependencyType.java +++ b/core/src/main/java/org/teavm/dependency/DependencyType.java @@ -16,18 +16,18 @@ package org.teavm.dependency; public class DependencyType { - private DependencyChecker dependencyChecker; + private DependencyAnalyzer dependencyAnalyzer; private String name; int index; - DependencyType(DependencyChecker dependencyChecker, String name, int index) { - this.dependencyChecker = dependencyChecker; + DependencyType(DependencyAnalyzer dependencyAnalyzer, String name, int index) { + this.dependencyAnalyzer = dependencyAnalyzer; this.name = name; this.index = index; } - DependencyChecker getDependencyChecker() { - return dependencyChecker; + DependencyAnalyzer getDependencyAnalyzer() { + return dependencyAnalyzer; } public String getName() { @@ -35,6 +35,6 @@ public class DependencyType { } public DependencyAgent getDependencyAgent() { - return dependencyChecker.getAgent(); + return dependencyAnalyzer.getAgent(); } } diff --git a/core/src/main/java/org/teavm/dependency/MethodDependency.java b/core/src/main/java/org/teavm/dependency/MethodDependency.java index 3a4e89195..b340f15f1 100644 --- a/core/src/main/java/org/teavm/dependency/MethodDependency.java +++ b/core/src/main/java/org/teavm/dependency/MethodDependency.java @@ -21,7 +21,7 @@ import org.teavm.model.MethodReader; import org.teavm.model.MethodReference; public class MethodDependency implements MethodDependencyInfo { - private DependencyChecker dependencyChecker; + private DependencyAnalyzer dependencyAnalyzer; DependencyNode[] variableNodes; private int parameterCount; DependencyNode resultNode; @@ -32,9 +32,9 @@ public class MethodDependency implements MethodDependencyInfo { DependencyPlugin dependencyPlugin; boolean dependencyPluginAttached; - MethodDependency(DependencyChecker dependencyChecker, DependencyNode[] variableNodes, int parameterCount, + MethodDependency(DependencyAnalyzer dependencyAnalyzer, DependencyNode[] variableNodes, int parameterCount, DependencyNode resultNode, DependencyNode thrown, MethodHolder method, MethodReference reference) { - this.dependencyChecker = dependencyChecker; + this.dependencyAnalyzer = dependencyAnalyzer; this.variableNodes = Arrays.copyOf(variableNodes, variableNodes.length); this.parameterCount = parameterCount; this.thrown = thrown; @@ -44,7 +44,7 @@ public class MethodDependency implements MethodDependencyInfo { } public DependencyAgent getDependencyAgent() { - return dependencyChecker.getAgent(); + return dependencyAnalyzer.getAgent(); } @Override @@ -101,11 +101,11 @@ public class MethodDependency implements MethodDependencyInfo { } public MethodDependency propagate(int parameterIndex, Class type) { - return propagate(parameterIndex, dependencyChecker.getType(type.getName())); + return propagate(parameterIndex, dependencyAnalyzer.getType(type.getName())); } public MethodDependency propagate(int parameterIndex, String type) { - return propagate(parameterIndex, dependencyChecker.getType(type)); + return propagate(parameterIndex, dependencyAnalyzer.getType(type)); } public MethodDependency propagate(int parameterIndex, DependencyType type) { @@ -117,7 +117,7 @@ public class MethodDependency implements MethodDependencyInfo { if (!used) { used = true; if (!isMissing()) { - dependencyChecker.scheduleMethodAnalysis(this); + dependencyAnalyzer.scheduleMethodAnalysis(this); } } } diff --git a/core/src/main/java/org/teavm/vm/TeaVM.java b/core/src/main/java/org/teavm/vm/TeaVM.java index fde502f81..53d706e5d 100644 --- a/core/src/main/java/org/teavm/vm/TeaVM.java +++ b/core/src/main/java/org/teavm/vm/TeaVM.java @@ -30,7 +30,7 @@ import java.util.stream.Collectors; import org.teavm.cache.NoCache; import org.teavm.common.ServiceRepository; import org.teavm.dependency.BootstrapMethodSubstitutor; -import org.teavm.dependency.DependencyChecker; +import org.teavm.dependency.DependencyAnalyzer; import org.teavm.dependency.DependencyInfo; import org.teavm.dependency.DependencyListener; import org.teavm.dependency.Linker; @@ -103,7 +103,7 @@ import org.teavm.vm.spi.TeaVMPlugin; */ public class TeaVM implements TeaVMHost, ServiceRepository { private final ClassReaderSource classSource; - private final DependencyChecker dependencyChecker; + private final DependencyAnalyzer dependencyAnalyzer; private final AccumulationDiagnostics diagnostics = new AccumulationDiagnostics(); private final ClassLoader classLoader; private final Map entryPoints = new HashMap<>(); @@ -125,7 +125,7 @@ public class TeaVM implements TeaVMHost, ServiceRepository { target = builder.target; classSource = builder.classSource; classLoader = builder.classLoader; - dependencyChecker = new DependencyChecker(this.classSource, classLoader, this, diagnostics); + dependencyAnalyzer = new DependencyAnalyzer(this.classSource, classLoader, this, diagnostics); progressListener = new TeaVMProgressListener() { @Override public TeaVMProgressFeedback progressReached(int progress) { return TeaVMProgressFeedback.CONTINUE; @@ -136,10 +136,10 @@ public class TeaVM implements TeaVMHost, ServiceRepository { }; for (ClassHolderTransformer transformer : target.getTransformers()) { - dependencyChecker.addClassTransformer(transformer); + dependencyAnalyzer.addClassTransformer(transformer); } for (DependencyListener listener : target.getDependencyListeners()) { - dependencyChecker.addDependencyListener(listener); + dependencyAnalyzer.addDependencyListener(listener); } for (TeaVMHostExtension extension : target.getHostExtensions()) { @@ -151,17 +151,17 @@ public class TeaVM implements TeaVMHost, ServiceRepository { @Override public void add(DependencyListener listener) { - dependencyChecker.addDependencyListener(listener); + dependencyAnalyzer.addDependencyListener(listener); } @Override public void add(ClassHolderTransformer transformer) { - dependencyChecker.addClassTransformer(transformer); + dependencyAnalyzer.addClassTransformer(transformer); } @Override public void add(MethodReference methodRef, BootstrapMethodSubstitutor substitutor) { - dependencyChecker.addBootstrapMethodSubstitutor(methodRef, substitutor); + dependencyAnalyzer.addBootstrapMethodSubstitutor(methodRef, substitutor); } @Override @@ -248,8 +248,8 @@ public class TeaVM implements TeaVMHost, ServiceRepository { + "for method " + ref); } } - TeaVMEntryPoint entryPoint = new TeaVMEntryPoint(name, ref, dependencyChecker.linkMethod(ref, null)); - dependencyChecker.linkClass(ref.getClassName(), null).initClass(null); + TeaVMEntryPoint entryPoint = new TeaVMEntryPoint(name, ref, dependencyAnalyzer.linkMethod(ref, null)); + dependencyAnalyzer.linkClass(ref.getClassName(), null).initClass(null); if (name != null) { entryPoints.put(name, entryPoint); } @@ -273,8 +273,8 @@ public class TeaVM implements TeaVMHost, ServiceRepository { } public TeaVMEntryPoint linkMethod(MethodReference ref) { - TeaVMEntryPoint entryPoint = new TeaVMEntryPoint("", ref, dependencyChecker.linkMethod(ref, null)); - dependencyChecker.linkClass(ref.getClassName(), null).initClass(null); + TeaVMEntryPoint entryPoint = new TeaVMEntryPoint("", ref, dependencyAnalyzer.linkMethod(ref, null)); + dependencyAnalyzer.linkClass(ref.getClassName(), null).initClass(null); return entryPoint; } @@ -283,7 +283,7 @@ public class TeaVM implements TeaVMHost, ServiceRepository { throw new IllegalArgumentException("Class with public name `" + name + "' already defined for class " + className); } - dependencyChecker.linkClass(className, null).initClass(null); + dependencyAnalyzer.linkClass(className, null).initClass(null); exportedClasses.put(name, className); } @@ -300,22 +300,22 @@ public class TeaVM implements TeaVMHost, ServiceRepository { /** * Gets a {@link ClassReaderSource} which is similar to that of {@link #getClassSource()}, * except that it also contains classes with applied transformations together with - * classes, generated via {@link DependencyChecker#submitClass(ClassHolder)}. + * classes, generated via {@link DependencyAnalyzer#submitClass(ClassHolder)}. */ public ClassReaderSource getDependencyClassSource() { - return dependencyChecker.getClassSource(); + return dependencyAnalyzer.getClassSource(); } public Collection getClasses() { - return dependencyChecker.getReachableClasses(); + return dependencyAnalyzer.getReachableClasses(); } public Collection getMethods() { - return dependencyChecker.getReachableMethods(); + return dependencyAnalyzer.getReachableMethods(); } public DependencyInfo getDependencyInfo() { - return dependencyChecker; + return dependencyAnalyzer; } public ListableClassReaderSource getWrittenClasses() { @@ -337,14 +337,14 @@ public class TeaVM implements TeaVMHost, ServiceRepository { target.setController(targetController); // Check dependencies - reportPhase(TeaVMPhase.DEPENDENCY_CHECKING, 1); + reportPhase(TeaVMPhase.DEPENDENCY_ANALYSIS, 1); if (wasCancelled()) { return; } - dependencyChecker.setInterruptor(() -> progressListener.progressReached(0) == TeaVMProgressFeedback.CONTINUE); - target.contributeDependencies(dependencyChecker); - dependencyChecker.processDependencies(); + dependencyAnalyzer.setInterruptor(() -> progressListener.progressReached(0) == TeaVMProgressFeedback.CONTINUE); + target.contributeDependencies(dependencyAnalyzer); + dependencyAnalyzer.processDependencies(); if (wasCancelled() || !diagnostics.getSevereProblems().isEmpty()) { return; } @@ -354,7 +354,7 @@ public class TeaVM implements TeaVMHost, ServiceRepository { if (wasCancelled()) { return; } - ListableClassHolderSource classSet = link(dependencyChecker); + ListableClassHolderSource classSet = link(dependencyAnalyzer); writtenClasses = classSet; if (wasCancelled()) { return; @@ -364,12 +364,12 @@ public class TeaVM implements TeaVMHost, ServiceRepository { reportPhase(TeaVMPhase.OPTIMIZATION, 1); if (!incremental) { - devirtualize(classSet, dependencyChecker); + devirtualize(classSet, dependencyAnalyzer); if (wasCancelled()) { return; } - inline(classSet, dependencyChecker); + inline(classSet, dependencyAnalyzer); if (wasCancelled()) { return; } @@ -543,7 +543,7 @@ public class TeaVM implements TeaVMHost, ServiceRepository { @Override public DependencyInfo getDependencyInfo() { - return dependencyChecker; + return dependencyAnalyzer; } @Override @@ -629,12 +629,12 @@ public class TeaVM implements TeaVMHost, ServiceRepository { @Override public ClassReaderSource getUnprocessedClassSource() { - return dependencyChecker.getClassSource(); + return dependencyAnalyzer.getClassSource(); } @Override public DependencyInfo getDependencyInfo() { - return dependencyChecker; + return dependencyAnalyzer; } @Override diff --git a/core/src/main/java/org/teavm/vm/TeaVMPhase.java b/core/src/main/java/org/teavm/vm/TeaVMPhase.java index 482b6243c..45f123116 100644 --- a/core/src/main/java/org/teavm/vm/TeaVMPhase.java +++ b/core/src/main/java/org/teavm/vm/TeaVMPhase.java @@ -16,7 +16,7 @@ package org.teavm.vm; public enum TeaVMPhase { - DEPENDENCY_CHECKING, + DEPENDENCY_ANALYSIS, LINKING, OPTIMIZATION, DECOMPILATION, diff --git a/core/src/main/java/org/teavm/vm/TeaVMTarget.java b/core/src/main/java/org/teavm/vm/TeaVMTarget.java index 0a3188eab..7214fcb72 100644 --- a/core/src/main/java/org/teavm/vm/TeaVMTarget.java +++ b/core/src/main/java/org/teavm/vm/TeaVMTarget.java @@ -17,7 +17,7 @@ package org.teavm.vm; import java.io.IOException; import java.util.List; -import org.teavm.dependency.DependencyChecker; +import org.teavm.dependency.DependencyAnalyzer; import org.teavm.dependency.DependencyListener; import org.teavm.model.ClassHolderTransformer; import org.teavm.model.ListableClassHolderSource; @@ -37,7 +37,7 @@ public interface TeaVMTarget { boolean requiresRegisterAllocation(); - void contributeDependencies(DependencyChecker dependencyChecker); + void contributeDependencies(DependencyAnalyzer dependencyAnalyzer); void afterOptimizations(Program program, MethodReader method, ListableClassReaderSource classSource); diff --git a/platform/src/main/java/org/teavm/platform/metadata/MetadataGeneratorContext.java b/platform/src/main/java/org/teavm/platform/metadata/MetadataGeneratorContext.java index fa3b1aa52..094cf2f64 100644 --- a/platform/src/main/java/org/teavm/platform/metadata/MetadataGeneratorContext.java +++ b/platform/src/main/java/org/teavm/platform/metadata/MetadataGeneratorContext.java @@ -30,7 +30,7 @@ import org.teavm.vm.TeaVM; */ public interface MetadataGeneratorContext extends ServiceRepository { /** - * Gets the collection of all classes that were achieved by the dependency checker. + * Gets the collection of all classes that were reached by the dependency analyzer. * * @return class source. */ diff --git a/platform/src/main/java/org/teavm/platform/plugin/AsyncMethodGenerator.java b/platform/src/main/java/org/teavm/platform/plugin/AsyncMethodGenerator.java index 1c2eb27bb..001b1185e 100644 --- a/platform/src/main/java/org/teavm/platform/plugin/AsyncMethodGenerator.java +++ b/platform/src/main/java/org/teavm/platform/plugin/AsyncMethodGenerator.java @@ -94,30 +94,30 @@ public class AsyncMethodGenerator implements Generator, DependencyPlugin { } @Override - public void methodReached(DependencyAgent checker, MethodDependency method, CallLocation location) { + public void methodReached(DependencyAgent agent, MethodDependency method, CallLocation location) { MethodReference ref = method.getReference(); MethodReference asyncRef = getAsyncReference(ref); - MethodDependency asyncMethod = checker.linkMethod(asyncRef, location); + MethodDependency asyncMethod = agent.linkMethod(asyncRef, location); int paramCount = ref.parameterCount(); for (int i = 0; i <= paramCount; ++i) { method.getVariable(i).connect(asyncMethod.getVariable(i)); } - asyncMethod.getVariable(paramCount + 1).propagate(checker.getType(AsyncCallbackWrapper.class.getName())); + asyncMethod.getVariable(paramCount + 1).propagate(agent.getType(AsyncCallbackWrapper.class.getName())); - MethodDependency completeMethod = checker.linkMethod( + MethodDependency completeMethod = agent.linkMethod( new MethodReference(AsyncCallbackWrapper.class, "complete", Object.class, void.class), null); if (method.getResult() != null) { - completeMethod.getVariable(1).connect(method.getResult(), type -> checker.getClassSource() + completeMethod.getVariable(1).connect(method.getResult(), type -> agent.getClassSource() .isSuperType(ref.getReturnType(), ValueType.object(type.getName())).orElse(false)); } completeMethod.use(); - MethodDependency errorMethod = checker.linkMethod(new MethodReference(AsyncCallbackWrapper.class, "error", + MethodDependency errorMethod = agent.linkMethod(new MethodReference(AsyncCallbackWrapper.class, "error", Throwable.class, void.class), null); errorMethod.getVariable(1).connect(method.getThrown()); errorMethod.use(); - checker.linkMethod(new MethodReference(AsyncCallbackWrapper.class, "create", + agent.linkMethod(new MethodReference(AsyncCallbackWrapper.class, "create", AsyncCallback.class, AsyncCallbackWrapper.class), null).use(); asyncMethod.use(); diff --git a/platform/src/main/java/org/teavm/platform/plugin/NewInstanceDependencySupport.java b/platform/src/main/java/org/teavm/platform/plugin/NewInstanceDependencySupport.java index e3ec92451..32137f0e4 100644 --- a/platform/src/main/java/org/teavm/platform/plugin/NewInstanceDependencySupport.java +++ b/platform/src/main/java/org/teavm/platform/plugin/NewInstanceDependencySupport.java @@ -53,10 +53,10 @@ public class NewInstanceDependencySupport extends AbstractDependencyListener { } } - private void attachConstructor(DependencyAgent checker, String type, CallLocation location) { + private void attachConstructor(DependencyAgent agent, String type, CallLocation location) { MethodReference ref = new MethodReference(type, "", ValueType.VOID); - MethodDependency methodDep = checker.linkMethod(ref, location); - methodDep.getVariable(0).propagate(checker.getType(type)); + MethodDependency methodDep = agent.linkMethod(ref, location); + methodDep.getVariable(0).propagate(agent.getType(type)); methodDep.use(); } } diff --git a/tests/src/test/java/org/teavm/dependency/DependencyTest.java b/tests/src/test/java/org/teavm/dependency/DependencyTest.java index 12246701a..29acb26ff 100644 --- a/tests/src/test/java/org/teavm/dependency/DependencyTest.java +++ b/tests/src/test/java/org/teavm/dependency/DependencyTest.java @@ -113,7 +113,7 @@ public class DependencyTest { vm.setProgressListener(new TeaVMProgressListener() { @Override public TeaVMProgressFeedback phaseStarted(TeaVMPhase phase, int count) { - return phase == TeaVMPhase.DEPENDENCY_CHECKING + return phase == TeaVMPhase.DEPENDENCY_ANALYSIS ? TeaVMProgressFeedback.CONTINUE : TeaVMProgressFeedback.CANCEL; } diff --git a/tools/cli/src/main/java/org/teavm/cli/TeaVMRunner.java b/tools/cli/src/main/java/org/teavm/cli/TeaVMRunner.java index 56874d9dd..2b95acb7b 100644 --- a/tools/cli/src/main/java/org/teavm/cli/TeaVMRunner.java +++ b/tools/cli/src/main/java/org/teavm/cli/TeaVMRunner.java @@ -552,14 +552,14 @@ public final class TeaVMRunner { } phaseStartTime = System.currentTimeMillis(); switch (phase) { - case DEPENDENCY_CHECKING: - System.out.print("Finding methods to decompile..."); + case DEPENDENCY_ANALYSIS: + System.out.print("Analyzing classes..."); break; case LINKING: System.out.print("Linking methods..."); break; case OPTIMIZATION: - System.out.print("Applying devirtualization..."); + System.out.print("Optimizing code..."); break; case DECOMPILATION: System.out.print("Decompiling..."); diff --git a/tools/eclipse/plugin/src/main/java/org/teavm/eclipse/TeaVMEclipseProgressListener.java b/tools/eclipse/plugin/src/main/java/org/teavm/eclipse/TeaVMEclipseProgressListener.java index ef4cb9e3e..ea9bfe72c 100644 --- a/tools/eclipse/plugin/src/main/java/org/teavm/eclipse/TeaVMEclipseProgressListener.java +++ b/tools/eclipse/plugin/src/main/java/org/teavm/eclipse/TeaVMEclipseProgressListener.java @@ -43,7 +43,7 @@ class TeaVMEclipseProgressListener implements TeaVMProgressListener { case DECOMPILATION: taskName = "Decompiling"; break; - case DEPENDENCY_CHECKING: + case DEPENDENCY_ANALYSIS: taskName = "Dependency checking"; break; case OPTIMIZATION: diff --git a/tools/idea/jps-plugin/src/main/java/org/teavm/idea/jps/TeaVMBuild.java b/tools/idea/jps-plugin/src/main/java/org/teavm/idea/jps/TeaVMBuild.java index 6bc1b9e36..402a50cc0 100644 --- a/tools/idea/jps-plugin/src/main/java/org/teavm/idea/jps/TeaVMBuild.java +++ b/tools/idea/jps-plugin/src/main/java/org/teavm/idea/jps/TeaVMBuild.java @@ -171,7 +171,7 @@ class TeaVMBuild { private static String phaseName(TeaVMPhase phase) { switch (phase) { - case DEPENDENCY_CHECKING: + case DEPENDENCY_ANALYSIS: return "Discovering classes to compile"; case LINKING: return "Resolving method invocations";