Skip to content

Commit

Permalink
Merge pull request #2025 from MarcMil/use-ordinary-maps
Browse files Browse the repository at this point in the history
Use ordinary maps for PAG
  • Loading branch information
StevenArzt authored Nov 22, 2023
2 parents 9427127 + 449558c commit baf1f34
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
6 changes: 1 addition & 5 deletions src/main/java/soot/jimple/spark/pag/PAG.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@
import soot.toolkits.scalar.Pair;
import soot.util.ArrayNumberer;
import soot.util.HashMultiMap;
import soot.util.LargeNumberedMap;
import soot.util.MultiMap;
import soot.util.queue.ChunkedQueue;
import soot.util.queue.QueueReader;
Expand Down Expand Up @@ -736,9 +735,6 @@ public LocalVarNode makeLocalVarNode(Object value, Type type, SootMethod method)
method = null;
} else if (value instanceof Local) {
Local val = (Local) value;
if (val.getNumber() == 0) {
Scene.v().getLocalNumberer().add(val);
}
LocalVarNode ret = localToNodeMap.get(val);
if (ret == null) {
localToNodeMap.put((Local) value, ret = new LocalVarNode(this, value, type, method));
Expand Down Expand Up @@ -1545,7 +1541,7 @@ protected <K extends Node> boolean addToMap(Map<K, Object> m, K key, Node value)
private OnFlyCallGraph ofcg;
private final ArrayList<VarNode> dereferences = new ArrayList<VarNode>();
protected TypeManager typeManager;
private final LargeNumberedMap<Local, LocalVarNode> localToNodeMap = new LargeNumberedMap<>(Scene.v().getLocalNumberer());
protected Map<Local, LocalVarNode> localToNodeMap = new HashMap<>();
private final Map<Value, NewInstanceNode> newInstToNodeMap = new HashMap<>();
public int maxFinishNumber = 0;
private Map<Node, Tag> nodeToTag;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@
* #L%
*/

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.Iterator;
Expand Down Expand Up @@ -95,7 +94,6 @@
import soot.jimple.StringConstant;
import soot.jimple.VirtualInvokeExpr;
import soot.jimple.spark.pag.AllocDotField;
import soot.jimple.spark.pag.PAG;
import soot.jimple.toolkits.annotation.nullcheck.NullnessAnalysis;
import soot.jimple.toolkits.callgraph.ConstantArrayAnalysis.ArrayTypes;
import soot.jimple.toolkits.callgraph.VirtualEdgesSummaries.DirectTarget;
Expand All @@ -113,7 +111,6 @@
import soot.util.LargeNumberedMap;
import soot.util.MultiMap;
import soot.util.NumberedString;
import soot.util.SmallNumberedMap;
import soot.util.StringNumberer;
import soot.util.queue.ChunkedQueue;
import soot.util.queue.QueueReader;
Expand Down Expand Up @@ -167,12 +164,12 @@ public class OnFlyCallGraphBuilder {
private final CallGraph cicg = Scene.v().internalMakeCallGraph();

// end type based reflection resolution
protected final LargeNumberedMap<Local, List<VirtualCallSite>> receiverToSites;
protected final Map<Local, List<VirtualCallSite>> receiverToSites;
protected final LargeNumberedMap<SootMethod, List<Local>> methodToReceivers;
protected final LargeNumberedMap<SootMethod, List<Local>> methodToInvokeBases;
protected final LargeNumberedMap<SootMethod, List<Local>> methodToInvokeArgs;
protected final LargeNumberedMap<SootMethod, List<Local>> methodToStringConstants;
protected final SmallNumberedMap<Local, List<VirtualCallSite>> stringConstToSites;
protected final Map<Local, List<VirtualCallSite>> stringConstToSites;

protected final HashSet<SootMethod> analyzedMethods = new HashSet<SootMethod>();
protected final MultiMap<Local, InvokeCallSite> baseToInvokeSite = new HashMultiMap<>();
Expand Down Expand Up @@ -212,13 +209,13 @@ public OnFlyCallGraphBuilder(ContextManager cm, ReachableMethods rm, boolean app
this.sigForName = nmbr.findOrAdd(JavaMethods.SIG_INIT);
}
{
this.receiverToSites = new LargeNumberedMap<Local, List<VirtualCallSite>>(sc.getLocalNumberer());
this.receiverToSites = new HashMap<Local, List<VirtualCallSite>>();
final IterableNumberer<SootMethod> methodNumberer = sc.getMethodNumberer();
this.methodToReceivers = new LargeNumberedMap<SootMethod, List<Local>>(methodNumberer);
this.methodToInvokeBases = new LargeNumberedMap<SootMethod, List<Local>>(methodNumberer);
this.methodToInvokeArgs = new LargeNumberedMap<SootMethod, List<Local>>(methodNumberer);
this.methodToStringConstants = new LargeNumberedMap<SootMethod, List<Local>>(methodNumberer);
this.stringConstToSites = new SmallNumberedMap<Local, List<VirtualCallSite>>();
this.stringConstToSites = new HashMap<Local, List<VirtualCallSite>>();
}

this.cm = cm;
Expand Down Expand Up @@ -877,7 +874,7 @@ public Set<Local> getReceiversOfVirtualEdge(VirtualEdgeTarget edgeTarget, Invoke
if (edgeTarget instanceof VirtualEdgesSummaries.IndirectTarget) {
VirtualEdgesSummaries.IndirectTarget indirectTarget = (VirtualEdgesSummaries.IndirectTarget) edgeTarget;
// Recursion case: We have an indirect target, which leads us to the statement where the local,
// that gets $this inside the callee, resides.
// that gets $this inside the callee, resides.

// First find the receiver of another call
Local l = getLocalForTarget(invokeExpr, edgeTarget);
Expand Down Expand Up @@ -908,7 +905,7 @@ public Set<Local> getReceiversOfVirtualEdge(VirtualEdgeTarget edgeTarget, Invoke

assert edgeTarget instanceof DirectTarget;
// Base case: Lookup the value based on the index referenced by the VirtualEdgeTarget.
// That local represents the $this local inside the callee.
// That local represents the $this local inside the callee.
Local l = getLocalForTarget(invokeExpr, edgeTarget);
return l == null ? Collections.emptySet() : Collections.singleton(l);
}
Expand Down

0 comments on commit baf1f34

Please sign in to comment.