soot.jimple.infoflow.solver.gcSolver.fpc.AbstrationDependencyGraph Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of soot-infoflow Show documentation
Show all versions of soot-infoflow Show documentation
Soot extending data flow tracking components for Java
The newest version!
package soot.jimple.infoflow.solver.gcSolver.fpc;
import heros.solver.Pair;
import soot.SootMethod;
import soot.jimple.infoflow.collect.ConcurrentHashSet;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.ReentrantLock;
public class AbstrationDependencyGraph implements IGraph> {
private final ReentrantLock lock = new ReentrantLock();
private final Set> nodes = new ConcurrentHashSet<>();
private final Map, Set>> succMap = new ConcurrentHashMap<>();
private final Map, Set>> predMap = new ConcurrentHashMap<>();
@Override
public Set> getNodes() {
return nodes;
}
@Override
public Set> succsOf(Pair node) {
return succMap.getOrDefault(node, Collections.emptySet());
}
@Override
public Set> predsOf(Pair node) {
return predMap.getOrDefault(node, Collections.emptySet());
}
@Override
public void addNode(Pair node) {
nodes.add(node);
}
@Override
public void addEdge(Pair n1, Pair n2) {
addNode(n1);
addNode(n2);
succMap.computeIfAbsent(n1, k -> new ConcurrentHashSet<>()).add(n2);
predMap.computeIfAbsent(n2, k -> new ConcurrentHashSet<>()).add(n1);
}
@Override
public boolean contains(Pair node) {
return nodes.contains(node);
}
@Override
public void removeEdge(Pair n1, Pair n2) {
succsOf(n1).remove(n2);
predsOf(n2).remove(n1);
}
@Override
public void remove(Pair node) {
nodes.remove(node);
for (Pair pred : predsOf(node)) {
removeEdge(pred, node);
}
for (Pair succ : succsOf(node)) {
removeEdge(node, succ);
}
}
public void lock() {
lock.lock();
}
public void unlock() {
if (lock.isHeldByCurrentThread()) {
lock.unlock();
}
}
public int nodeSize() {
return this.nodes.size();
}
public int edgeSize() {
int ret = 0;
for (Set> vs : succMap.values()) {
ret += vs.size();
}
return ret;
}
public Set> reachableClosure(Pair source) {
final Set> visited = new ConcurrentHashSet<>();
final Deque> stack = new ArrayDeque<>();
stack.push(source);
while (!stack.isEmpty()) {
final Pair node = stack.pop();
visited.add(node);
succsOf(node).stream().filter(n -> !visited.contains(n)).forEach(stack::push);
}
return visited;
}
}