diff --git a/core/src/main/java/org/teavm/callgraph/CallGraph.java b/core/src/main/java/org/teavm/callgraph/CallGraph.java index 213ce96d7..c626b5d1b 100644 --- a/core/src/main/java/org/teavm/callgraph/CallGraph.java +++ b/core/src/main/java/org/teavm/callgraph/CallGraph.java @@ -36,6 +36,4 @@ public interface CallGraph { CallGraphNode getNode(MethodReference method); Collection getFieldAccess(FieldReference reference); - - Collection getClassAccess(String className); } diff --git a/core/src/main/java/org/teavm/callgraph/CallGraphNode.java b/core/src/main/java/org/teavm/callgraph/CallGraphNode.java index 445df4552..eba99593a 100644 --- a/core/src/main/java/org/teavm/callgraph/CallGraphNode.java +++ b/core/src/main/java/org/teavm/callgraph/CallGraphNode.java @@ -52,6 +52,4 @@ public interface CallGraphNode { Collection getCallerCallSites(); Collection getFieldAccessSites(); - - Collection getClassAccessSites(); } diff --git a/core/src/main/java/org/teavm/callgraph/ClassAccessSite.java b/core/src/main/java/org/teavm/callgraph/ClassAccessSite.java deleted file mode 100644 index a51244e69..000000000 --- a/core/src/main/java/org/teavm/callgraph/ClassAccessSite.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2014 Alexey Andreev. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.teavm.callgraph; - -import org.teavm.model.TextLocation; - -public interface ClassAccessSite { - TextLocation getLocation(); - - CallGraphNode getCallee(); - - String getClassName(); -} diff --git a/core/src/main/java/org/teavm/callgraph/DefaultCallGraph.java b/core/src/main/java/org/teavm/callgraph/DefaultCallGraph.java index f907552ef..5bacf9bbb 100644 --- a/core/src/main/java/org/teavm/callgraph/DefaultCallGraph.java +++ b/core/src/main/java/org/teavm/callgraph/DefaultCallGraph.java @@ -35,7 +35,6 @@ import org.teavm.model.MethodReference; public class DefaultCallGraph implements CallGraph, Serializable { Map nodes = new LinkedHashMap<>(); Map> fieldAccessSites = new LinkedHashMap<>(); - Map> classAccessSites = new LinkedHashMap<>(); @Override public DefaultCallGraphNode getNode(MethodReference method) { @@ -52,16 +51,6 @@ public class DefaultCallGraph implements CallGraph, Serializable { fieldAccessSites.computeIfAbsent(accessSite.getField(), k -> new HashSet<>()).add(accessSite); } - @Override - public Collection getClassAccess(String className) { - Set resultSet = classAccessSites.get(className); - return resultSet != null ? Collections.unmodifiableSet(resultSet) : Collections.emptySet(); - } - - void addClassAccess(DefaultClassAccessSite accessSite) { - classAccessSites.computeIfAbsent(accessSite.getClassName(), k -> new HashSet<>()).add(accessSite); - } - private void writeObject(ObjectOutputStream out) throws IOException { SerializableCallGraphBuilder builder = new SerializableCallGraphBuilder(); out.writeObject(builder.build(this)); @@ -71,7 +60,6 @@ public class DefaultCallGraph implements CallGraph, Serializable { SerializableCallGraph scg = (SerializableCallGraph) in.readObject(); nodes = new LinkedHashMap<>(); fieldAccessSites = new LinkedHashMap<>(); - classAccessSites = new LinkedHashMap<>(); new CallGraphBuilder().build(scg, this); } @@ -83,12 +71,9 @@ public class DefaultCallGraph implements CallGraph, Serializable { ObjectIntMap callSiteToIndex = new ObjectIntOpenHashMap<>(); List fieldAccessList = new ArrayList<>(); ObjectIntMap fieldAccessToIndex = new ObjectIntOpenHashMap<>(); - List classAccessList = new ArrayList<>(); - ObjectIntMap classAccessToIndex = new ObjectIntOpenHashMap<>(); List nodesToProcess = new ArrayList<>(); List callSitesToProcess = new ArrayList<>(); List fieldAccessToProcess = new ArrayList<>(); - List classAccessToProcess = new ArrayList<>(); SerializableCallGraph build(DefaultCallGraph cg) { SerializableCallGraph scg = new SerializableCallGraph(); @@ -99,9 +84,6 @@ public class DefaultCallGraph implements CallGraph, Serializable { scg.fieldAccessIndexes = cg.fieldAccessSites.values().stream() .flatMapToInt(accessSites -> accessSites.stream().mapToInt(this::getFieldAccess)) .toArray(); - scg.classAccessIndexes = cg.classAccessSites.values().stream() - .flatMapToInt(accessSites -> accessSites.stream().mapToInt(this::getClassAccess)) - .toArray(); while (step()) { // just repeat @@ -110,13 +92,12 @@ public class DefaultCallGraph implements CallGraph, Serializable { scg.nodes = nodes.toArray(new SerializableCallGraph.Node[0]); scg.callSites = callSites.toArray(new SerializableCallGraph.CallSite[0]); scg.fieldAccessList = fieldAccessList.toArray(new SerializableCallGraph.FieldAccess[0]); - scg.classAccessList = classAccessList.toArray(new SerializableCallGraph.ClassAccess[0]); return scg; } boolean step() { - return processNodes() | processCallSites() | processFieldAccess() | processClassAccess(); + return processNodes() | processCallSites() | processFieldAccess(); } boolean processNodes() { @@ -134,9 +115,6 @@ public class DefaultCallGraph implements CallGraph, Serializable { serializableNode.fieldAccessSites = node.getFieldAccessSites().stream() .mapToInt(this::getFieldAccess) .toArray(); - serializableNode.classAccessSites = node.getClassAccessSites().stream() - .mapToInt(this::getClassAccess) - .toArray(); hasAny = true; } nodesToProcess.clear(); @@ -171,20 +149,6 @@ public class DefaultCallGraph implements CallGraph, Serializable { return hasAny; } - boolean processClassAccess() { - boolean hasAny = false; - for (DefaultClassAccessSite accessSite : classAccessToProcess.toArray(new DefaultClassAccessSite[0])) { - int index = classAccessToIndex.get(accessSite); - SerializableCallGraph.ClassAccess sca = classAccessList.get(index); - sca.location = accessSite.getLocation(); - sca.className = accessSite.getClassName(); - sca.callee = getNode(accessSite.getCallee()); - hasAny = true; - } - classAccessToProcess.clear(); - return hasAny; - } - private int getNode(DefaultCallGraphNode node) { int index = nodeToIndex.getOrDefault(node, -1); if (index < 0) { @@ -217,24 +181,12 @@ public class DefaultCallGraph implements CallGraph, Serializable { } return index; } - - private int getClassAccess(DefaultClassAccessSite classAccessSite) { - int index = classAccessToIndex.getOrDefault(classAccessSite, -1); - if (index < 0) { - index = classAccessToIndex.size(); - classAccessToIndex.put(classAccessSite, index); - classAccessList.add(new SerializableCallGraph.ClassAccess()); - classAccessToProcess.add(classAccessSite); - } - return index; - } } static class CallGraphBuilder { List nodes = new ArrayList<>(); List callSites = new ArrayList<>(); List fieldAccessList = new ArrayList<>(); - List classAccessList = new ArrayList<>(); void build(SerializableCallGraph scg, DefaultCallGraph cg) { for (SerializableCallGraph.Node serializableNode : scg.nodes) { @@ -246,9 +198,6 @@ public class DefaultCallGraph implements CallGraph, Serializable { for (SerializableCallGraph.FieldAccess sfa : scg.fieldAccessList) { fieldAccessList.add(new DefaultFieldAccessSite(sfa.location, nodes.get(sfa.callee), sfa.field)); } - for (SerializableCallGraph.ClassAccess sca : scg.classAccessList) { - classAccessList.add(new DefaultClassAccessSite(sca.location, nodes.get(sca.callee), sca.className)); - } for (int index : scg.nodeIndexes) { DefaultCallGraphNode node = nodes.get(index); @@ -257,9 +206,6 @@ public class DefaultCallGraph implements CallGraph, Serializable { for (int index : scg.fieldAccessIndexes) { cg.addFieldAccess(fieldAccessList.get(index)); } - for (int index : scg.classAccessIndexes) { - cg.addClassAccess(classAccessList.get(index)); - } } } } diff --git a/core/src/main/java/org/teavm/callgraph/DefaultCallGraphNode.java b/core/src/main/java/org/teavm/callgraph/DefaultCallGraphNode.java index 5ebe3dffc..24efc7b54 100644 --- a/core/src/main/java/org/teavm/callgraph/DefaultCallGraphNode.java +++ b/core/src/main/java/org/teavm/callgraph/DefaultCallGraphNode.java @@ -28,14 +28,12 @@ import org.teavm.model.TextLocation; public class DefaultCallGraphNode implements CallGraphNode { private DefaultCallGraph graph; private MethodReference method; - Set callSites = new HashSet<>(); + private Set callSites = new HashSet<>(); private Set safeCallSites; - List callerCallSites = new ArrayList<>(); + private List callerCallSites = new ArrayList<>(); private List safeCallersCallSites; - Set fieldAccessSites = new HashSet<>(); + private Set fieldAccessSites = new HashSet<>(); private Set safeFieldAccessSites; - Set classAccessSites = new HashSet<>(); - private Set safeClassAccessSites; DefaultCallGraphNode(DefaultCallGraph graph, MethodReference method) { this.graph = graph; @@ -100,22 +98,4 @@ public class DefaultCallGraphNode implements CallGraphNode { return false; } } - - @Override - public Collection getClassAccessSites() { - if (safeClassAccessSites == null) { - safeClassAccessSites = Collections.unmodifiableSet(classAccessSites); - } - return safeClassAccessSites; - } - - public boolean addClassAccess(String className, TextLocation location) { - DefaultClassAccessSite site = new DefaultClassAccessSite(location, this, className); - if (classAccessSites.add(site)) { - graph.addClassAccess(site); - return true; - } else { - return false; - } - } } diff --git a/core/src/main/java/org/teavm/callgraph/DefaultClassAccessSite.java b/core/src/main/java/org/teavm/callgraph/DefaultClassAccessSite.java deleted file mode 100644 index f9179923e..000000000 --- a/core/src/main/java/org/teavm/callgraph/DefaultClassAccessSite.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2014 Alexey Andreev. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.teavm.callgraph; - -import java.io.Serializable; -import java.util.Objects; -import org.teavm.model.TextLocation; - -public class DefaultClassAccessSite implements ClassAccessSite, Serializable { - private TextLocation location; - private DefaultCallGraphNode callee; - private String className; - - DefaultClassAccessSite(TextLocation location, DefaultCallGraphNode callee, String className) { - this.location = location; - this.callee = callee; - this.className = className; - } - - @Override - public TextLocation getLocation() { - return location; - } - - @Override - public DefaultCallGraphNode getCallee() { - return callee; - } - - @Override - public String getClassName() { - return className; - } - - @Override - public int hashCode() { - return Objects.hash(location, callee, className); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (!(obj instanceof DefaultClassAccessSite)) { - return false; - } - DefaultClassAccessSite other = (DefaultClassAccessSite) obj; - return Objects.equals(location, other.location) - && Objects.equals(callee, other.callee) - && Objects.equals(className, other.className); - } -} diff --git a/core/src/main/java/org/teavm/callgraph/SerializableCallGraph.java b/core/src/main/java/org/teavm/callgraph/SerializableCallGraph.java index 52fd70d5b..d44c1aab6 100644 --- a/core/src/main/java/org/teavm/callgraph/SerializableCallGraph.java +++ b/core/src/main/java/org/teavm/callgraph/SerializableCallGraph.java @@ -27,14 +27,12 @@ class SerializableCallGraph implements Serializable { Node[] nodes; CallSite[] callSites; FieldAccess[] fieldAccessList; - ClassAccess[] classAccessList; static class Node implements Serializable { MethodReference method; int[] callSites; int[] callerCallSites; int[] fieldAccessSites; - int[] classAccessSites; } static class CallSite implements Serializable { @@ -48,10 +46,4 @@ class SerializableCallGraph implements Serializable { int callee; FieldReference field; } - - static class ClassAccess implements Serializable { - TextLocation location; - int callee; - String className; - } }