mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
Remove unused parts of call graph API
This commit is contained in:
parent
edfbe01a7f
commit
1b0bacd90c
|
@ -36,6 +36,4 @@ public interface CallGraph {
|
|||
CallGraphNode getNode(MethodReference method);
|
||||
|
||||
Collection<? extends FieldAccessSite> getFieldAccess(FieldReference reference);
|
||||
|
||||
Collection<? extends ClassAccessSite> getClassAccess(String className);
|
||||
}
|
||||
|
|
|
@ -52,6 +52,4 @@ public interface CallGraphNode {
|
|||
Collection<? extends CallSite> getCallerCallSites();
|
||||
|
||||
Collection<? extends FieldAccessSite> getFieldAccessSites();
|
||||
|
||||
Collection<? extends ClassAccessSite> getClassAccessSites();
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
|
@ -35,7 +35,6 @@ import org.teavm.model.MethodReference;
|
|||
public class DefaultCallGraph implements CallGraph, Serializable {
|
||||
Map<MethodReference, DefaultCallGraphNode> nodes = new LinkedHashMap<>();
|
||||
Map<FieldReference, Set<DefaultFieldAccessSite>> fieldAccessSites = new LinkedHashMap<>();
|
||||
Map<String, Set<DefaultClassAccessSite>> 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<DefaultClassAccessSite> getClassAccess(String className) {
|
||||
Set<DefaultClassAccessSite> 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<DefaultCallSite> callSiteToIndex = new ObjectIntOpenHashMap<>();
|
||||
List<SerializableCallGraph.FieldAccess> fieldAccessList = new ArrayList<>();
|
||||
ObjectIntMap<DefaultFieldAccessSite> fieldAccessToIndex = new ObjectIntOpenHashMap<>();
|
||||
List<SerializableCallGraph.ClassAccess> classAccessList = new ArrayList<>();
|
||||
ObjectIntMap<DefaultClassAccessSite> classAccessToIndex = new ObjectIntOpenHashMap<>();
|
||||
List<DefaultCallGraphNode> nodesToProcess = new ArrayList<>();
|
||||
List<DefaultCallSite> callSitesToProcess = new ArrayList<>();
|
||||
List<DefaultFieldAccessSite> fieldAccessToProcess = new ArrayList<>();
|
||||
List<DefaultClassAccessSite> 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<DefaultCallGraphNode> nodes = new ArrayList<>();
|
||||
List<DefaultCallSite> callSites = new ArrayList<>();
|
||||
List<DefaultFieldAccessSite> fieldAccessList = new ArrayList<>();
|
||||
List<DefaultClassAccessSite> 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,14 +28,12 @@ import org.teavm.model.TextLocation;
|
|||
public class DefaultCallGraphNode implements CallGraphNode {
|
||||
private DefaultCallGraph graph;
|
||||
private MethodReference method;
|
||||
Set<DefaultCallSite> callSites = new HashSet<>();
|
||||
private Set<DefaultCallSite> callSites = new HashSet<>();
|
||||
private Set<DefaultCallSite> safeCallSites;
|
||||
List<DefaultCallSite> callerCallSites = new ArrayList<>();
|
||||
private List<DefaultCallSite> callerCallSites = new ArrayList<>();
|
||||
private List<DefaultCallSite> safeCallersCallSites;
|
||||
Set<DefaultFieldAccessSite> fieldAccessSites = new HashSet<>();
|
||||
private Set<DefaultFieldAccessSite> fieldAccessSites = new HashSet<>();
|
||||
private Set<DefaultFieldAccessSite> safeFieldAccessSites;
|
||||
Set<DefaultClassAccessSite> classAccessSites = new HashSet<>();
|
||||
private Set<DefaultClassAccessSite> safeClassAccessSites;
|
||||
|
||||
DefaultCallGraphNode(DefaultCallGraph graph, MethodReference method) {
|
||||
this.graph = graph;
|
||||
|
@ -100,22 +98,4 @@ public class DefaultCallGraphNode implements CallGraphNode {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<DefaultClassAccessSite> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user