use of soot.jimple.spark.sets.P2SetVisitor in project soot by Sable.
the class DemandCSPointsTo method checkContextsForAllocsCache.
protected PointsToSetInternal checkContextsForAllocsCache(VarAndContext varAndContext, AllocAndContextSet ret, PointsToSetInternal locs) {
PointsToSetInternal retSet = null;
if (contextsForAllocsCache.containsKey(varAndContext)) {
for (AllocAndContext allocAndContext : contextsForAllocsCache.get(varAndContext).getO2()) {
if (locs.contains(allocAndContext.alloc)) {
ret.add(allocAndContext);
}
}
final PointsToSetInternal oldLocs = contextsForAllocsCache.get(varAndContext).getO1();
final PointsToSetInternal tmpSet = new HybridPointsToSet(locs.getType(), pag);
locs.forall(new P2SetVisitor() {
@Override
public void visit(Node n) {
if (!oldLocs.contains(n)) {
tmpSet.add(n);
}
}
});
retSet = tmpSet;
oldLocs.addAll(tmpSet, null);
} else {
PointsToSetInternal storedSet = new HybridPointsToSet(locs.getType(), pag);
storedSet.addAll(locs, null);
contextsForAllocsCache.put(varAndContext, new Pair<PointsToSetInternal, AllocAndContextSet>(storedSet, new AllocAndContextSet()));
retSet = locs;
}
return retSet;
}
use of soot.jimple.spark.sets.P2SetVisitor in project soot by Sable.
the class PAG method reachingObjectsInternal.
private PointsToSet reachingObjectsInternal(PointsToSet s, final SparkField f) {
if (getOpts().field_based() || getOpts().vta()) {
VarNode n = findGlobalVarNode(f);
if (n == null) {
return EmptyPointsToSet.v();
}
return n.getP2Set();
}
if ((getOpts()).propagator() == SparkOptions.propagator_alias) {
throw new RuntimeException("The alias edge propagator does not compute points-to information for instance fields! Use a different propagator.");
}
PointsToSetInternal bases = (PointsToSetInternal) s;
final PointsToSetInternal ret = setFactory.newSet((f instanceof SootField) ? ((SootField) f).getType() : null, this);
bases.forall(new P2SetVisitor() {
public final void visit(Node n) {
Node nDotF = ((AllocNode) n).dot(f);
if (nDotF != null)
ret.addAll(nDotF.getP2Set(), null);
}
});
return ret;
}
use of soot.jimple.spark.sets.P2SetVisitor in project soot by Sable.
the class PAGDumper method dumpPointsToSets.
public void dumpPointsToSets() {
try {
final PrintWriter file = new PrintWriter(new FileOutputStream(new File(output_dir, "solution")));
file.println("Solution:");
for (Iterator vnIt = pag.getVarNodeNumberer().iterator(); vnIt.hasNext(); ) {
final VarNode vn = (VarNode) vnIt.next();
if (vn.getReplacement() != vn) {
continue;
}
PointsToSetInternal p2set = vn.getP2Set();
if (p2set == null)
continue;
p2set.forall(new P2SetVisitor() {
public final void visit(Node n) {
try {
dumpNode(vn, file);
file.print(" ");
dumpNode(n, file);
file.println("");
} catch (IOException e) {
throw new RuntimeException("Couldn't dump solution." + e);
}
}
});
}
file.close();
} catch (IOException e) {
throw new RuntimeException("Couldn't dump solution." + e);
}
}
use of soot.jimple.spark.sets.P2SetVisitor in project soot by Sable.
the class SparkTransformer method addTags.
protected void addTags(PAG pag) {
final Tag unknown = new StringTag("Untagged Spark node");
final Map<Node, Tag> nodeToTag = pag.getNodeTags();
for (final SootClass c : Scene.v().getClasses()) {
for (final SootMethod m : c.getMethods()) {
if (!m.isConcrete())
continue;
if (!m.hasActiveBody())
continue;
for (final Unit u : m.getActiveBody().getUnits()) {
final Stmt s = (Stmt) u;
if (s instanceof DefinitionStmt) {
Value lhs = ((DefinitionStmt) s).getLeftOp();
VarNode v = null;
if (lhs instanceof Local) {
v = pag.findLocalVarNode(lhs);
} else if (lhs instanceof FieldRef) {
v = pag.findGlobalVarNode(((FieldRef) lhs).getField());
}
if (v != null) {
PointsToSetInternal p2set = v.getP2Set();
p2set.forall(new P2SetVisitor() {
public final void visit(Node n) {
addTag(s, n, nodeToTag, unknown);
}
});
Node[] simpleSources = pag.simpleInvLookup(v);
for (Node element : simpleSources) {
addTag(s, element, nodeToTag, unknown);
}
simpleSources = pag.allocInvLookup(v);
for (Node element : simpleSources) {
addTag(s, element, nodeToTag, unknown);
}
simpleSources = pag.loadInvLookup(v);
for (Node element : simpleSources) {
addTag(s, element, nodeToTag, unknown);
}
}
}
}
}
}
}
use of soot.jimple.spark.sets.P2SetVisitor in project soot by Sable.
the class PropAlias method handleVarNode.
/**
* Propagates new points-to information of node src to all its successors.
*/
protected final boolean handleVarNode(final VarNode src) {
boolean ret = false;
if (src.getReplacement() != src)
throw new RuntimeException("Got bad node " + src + " with rep " + src.getReplacement());
final PointsToSetInternal newP2Set = src.getP2Set().getNewSet();
if (newP2Set.isEmpty())
return false;
if (ofcg != null) {
QueueReader<Node> addedEdges = pag.edgeReader();
ofcg.updatedNode(src);
ofcg.build();
while (addedEdges.hasNext()) {
Node addedSrc = (Node) addedEdges.next();
Node addedTgt = (Node) addedEdges.next();
ret = true;
if (addedSrc instanceof VarNode) {
VarNode edgeSrc = (VarNode) addedSrc;
if (addedTgt instanceof VarNode) {
VarNode edgeTgt = (VarNode) addedTgt;
if (edgeTgt.makeP2Set().addAll(edgeSrc.getP2Set(), null))
addToWorklist(edgeTgt);
} else if (addedTgt instanceof NewInstanceNode) {
NewInstanceNode edgeTgt = (NewInstanceNode) addedTgt.getReplacement();
if (edgeTgt.makeP2Set().addAll(edgeSrc.getP2Set(), null)) {
for (Node element : pag.assignInstanceLookup(edgeTgt)) {
addToWorklist((VarNode) element);
}
}
}
} else if (addedSrc instanceof AllocNode) {
AllocNode edgeSrc = (AllocNode) addedSrc;
VarNode edgeTgt = (VarNode) addedTgt;
if (edgeTgt.makeP2Set().add(edgeSrc))
addToWorklist(edgeTgt);
} else if (addedSrc instanceof NewInstanceNode && addedTgt instanceof VarNode) {
final NewInstanceNode edgeSrc = (NewInstanceNode) addedSrc.getReplacement();
final VarNode edgeTgt = (VarNode) addedTgt.getReplacement();
addedSrc.getP2Set().forall(new P2SetVisitor() {
@Override
public void visit(Node n) {
if (n instanceof ClassConstantNode) {
ClassConstantNode ccn = (ClassConstantNode) n;
Type ccnType = ccn.getClassConstant().toSootType();
// If the referenced class has not been loaded,
// we do this now
SootClass targetClass = ((RefType) ccnType).getSootClass();
if (targetClass.resolvingLevel() == SootClass.DANGLING)
Scene.v().forceResolve(targetClass.getName(), SootClass.SIGNATURES);
edgeTgt.makeP2Set().add(pag.makeAllocNode(edgeSrc.getValue(), ccnType, ccn.getMethod()));
addToWorklist(edgeTgt);
}
}
});
}
FieldRefNode frn = null;
if (addedSrc instanceof FieldRefNode)
frn = (FieldRefNode) addedSrc;
if (addedTgt instanceof FieldRefNode)
frn = (FieldRefNode) addedTgt;
if (frn != null) {
VarNode base = frn.getBase();
if (fieldToBase.put(frn.getField(), base)) {
aliasWorkList.add(base);
}
}
}
}
Node[] simpleTargets = pag.simpleLookup(src);
for (Node element : simpleTargets) {
if (element.makeP2Set().addAll(newP2Set, null)) {
addToWorklist((VarNode) element);
ret = true;
}
}
Node[] storeTargets = pag.storeLookup(src);
for (Node element : storeTargets) {
final FieldRefNode fr = (FieldRefNode) element;
if (fr.makeP2Set().addAll(newP2Set, null)) {
fieldRefWorkList.add(fr);
ret = true;
}
}
src.getP2Set().flushNew();
return ret;
}
Aggregations