use of soot.jimple.spark.pag.FieldRefNode in project soot by Sable.
the class PropAlias method propagate.
/**
* Actually does the propagation.
*/
public final void propagate() {
ofcg = pag.getOnFlyCallGraph();
new TopoSorter(pag, false).sort();
for (Object object : pag.loadSources()) {
final FieldRefNode fr = (FieldRefNode) object;
fieldToBase.put(fr.getField(), fr.getBase());
}
for (Object object : pag.storeInvSources()) {
final FieldRefNode fr = (FieldRefNode) object;
fieldToBase.put(fr.getField(), fr.getBase());
}
for (Object object : pag.allocSources()) {
handleAllocNode((AllocNode) object);
}
boolean verbose = pag.getOpts().verbose();
do {
if (verbose) {
logger.debug("Worklist has " + varNodeWorkList.size() + " nodes.");
}
aliasWorkList = new HashSet<VarNode>();
while (!varNodeWorkList.isEmpty()) {
VarNode src = varNodeWorkList.iterator().next();
varNodeWorkList.remove(src);
aliasWorkList.add(src);
handleVarNode(src);
}
if (verbose) {
logger.debug("Now handling field references");
}
for (VarNode src : aliasWorkList) {
for (FieldRefNode srcFr : src.getAllFieldRefs()) {
SparkField field = srcFr.getField();
for (VarNode dst : fieldToBase.get(field)) {
if (src.getP2Set().hasNonEmptyIntersection(dst.getP2Set())) {
FieldRefNode dstFr = dst.dot(field);
aliasEdges.put(srcFr, dstFr);
aliasEdges.put(dstFr, srcFr);
fieldRefWorkList.add(srcFr);
fieldRefWorkList.add(dstFr);
if (makeP2Set(dstFr).addAll(srcFr.getP2Set().getOldSet(), null)) {
outFieldRefWorkList.add(dstFr);
}
if (makeP2Set(srcFr).addAll(dstFr.getP2Set().getOldSet(), null)) {
outFieldRefWorkList.add(srcFr);
}
}
}
}
}
for (FieldRefNode src : fieldRefWorkList) {
for (FieldRefNode dst : aliasEdges.get(src)) {
if (makeP2Set(dst).addAll(src.getP2Set().getNewSet(), null)) {
outFieldRefWorkList.add(dst);
}
}
src.getP2Set().flushNew();
}
fieldRefWorkList = new HashSet<FieldRefNode>();
for (FieldRefNode src : outFieldRefWorkList) {
PointsToSetInternal set = getP2Set(src).getNewSet();
if (set.isEmpty())
continue;
Node[] targets = pag.loadLookup(src);
for (Node element0 : targets) {
VarNode target = (VarNode) element0;
if (target.makeP2Set().addAll(set, null)) {
addToWorklist(target);
}
}
getP2Set(src).flushNew();
}
outFieldRefWorkList = new HashSet<FieldRefNode>();
} while (!varNodeWorkList.isEmpty());
}
use of soot.jimple.spark.pag.FieldRefNode in project soot by Sable.
the class PropIter method propagate.
/**
* Actually does the propagation.
*/
public final void propagate() {
final OnFlyCallGraph ofcg = pag.getOnFlyCallGraph();
new TopoSorter(pag, false).sort();
for (Object object : pag.allocSources()) {
handleAllocNode((AllocNode) object);
}
int iteration = 1;
boolean change;
do {
change = false;
TreeSet<VarNode> simpleSources = new TreeSet<VarNode>(pag.simpleSources());
if (pag.getOpts().verbose()) {
logger.debug("Iteration " + (iteration++));
}
for (VarNode object : simpleSources) {
change = handleSimples(object) | change;
}
if (ofcg != null) {
QueueReader<Node> addedEdges = pag.edgeReader();
for (VarNode src : pag.getVarNodeNumberer()) {
ofcg.updatedNode(src);
}
ofcg.build();
while (addedEdges.hasNext()) {
Node addedSrc = (Node) addedEdges.next();
Node addedTgt = (Node) addedEdges.next();
change = true;
if (addedSrc instanceof VarNode) {
PointsToSetInternal p2set = ((VarNode) addedSrc).getP2Set();
if (p2set != null)
p2set.unFlushNew();
} else if (addedSrc instanceof AllocNode) {
((VarNode) addedTgt).makeP2Set().add(addedSrc);
}
}
if (change) {
new TopoSorter(pag, false).sort();
}
}
for (FieldRefNode object : pag.loadSources()) {
change = handleLoads(object) | change;
}
for (VarNode object : pag.storeSources()) {
change = handleStores(object) | change;
}
for (NewInstanceNode object : pag.assignInstanceSources()) {
change = handleNewInstances(object) | change;
}
} while (change);
}
use of soot.jimple.spark.pag.FieldRefNode in project soot by Sable.
the class PropWorklist method propagate.
/**
* Actually does the propagation.
*/
public final void propagate() {
ofcg = pag.getOnFlyCallGraph();
new TopoSorter(pag, false).sort();
for (AllocNode object : pag.allocSources()) {
handleAllocNode(object);
}
boolean verbose = pag.getOpts().verbose();
do {
if (verbose) {
logger.debug("Worklist has " + varNodeWorkList.size() + " nodes.");
}
while (!varNodeWorkList.isEmpty()) {
VarNode src = varNodeWorkList.iterator().next();
varNodeWorkList.remove(src);
handleVarNode(src);
}
if (verbose) {
logger.debug("Now handling field references");
}
for (Object object : pag.storeSources()) {
final VarNode src = (VarNode) object;
Node[] targets = pag.storeLookup(src);
for (Node element0 : targets) {
final FieldRefNode target = (FieldRefNode) element0;
target.getBase().makeP2Set().forall(new P2SetVisitor() {
public final void visit(Node n) {
AllocDotField nDotF = pag.makeAllocDotField((AllocNode) n, target.getField());
if (ofcg != null) {
ofcg.updatedFieldRef(nDotF, src.getP2Set());
}
nDotF.makeP2Set().addAll(src.getP2Set(), null);
}
});
}
}
HashSet<Object[]> edgesToPropagate = new HashSet<Object[]>();
for (Object object : pag.loadSources()) {
handleFieldRefNode((FieldRefNode) object, edgesToPropagate);
}
Set<PointsToSetInternal> nodesToFlush = Collections.newSetFromMap(new IdentityHashMap<PointsToSetInternal, Boolean>());
for (Object[] pair : edgesToPropagate) {
PointsToSetInternal nDotF = (PointsToSetInternal) pair[0];
PointsToSetInternal newP2Set = nDotF.getNewSet();
VarNode loadTarget = (VarNode) pair[1];
if (loadTarget.makeP2Set().addAll(newP2Set, null)) {
varNodeWorkList.add(loadTarget);
}
nodesToFlush.add(nDotF);
}
for (PointsToSetInternal nDotF : nodesToFlush) {
nDotF.flushNew();
}
} while (!varNodeWorkList.isEmpty());
}
use of soot.jimple.spark.pag.FieldRefNode in project soot by Sable.
the class PropWorklist method handleVarNode.
/**
* Propagates new points-to information of node src to all its successors.
*/
protected final boolean handleVarNode(final VarNode src) {
boolean ret = false;
boolean flush = true;
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.getReplacement();
if (addedTgt instanceof VarNode) {
VarNode edgeTgt = (VarNode) addedTgt.getReplacement();
if (edgeTgt.makeP2Set().addAll(edgeSrc.getP2Set(), null)) {
varNodeWorkList.add(edgeTgt);
if (edgeTgt == src)
flush = false;
}
} else if (addedTgt instanceof NewInstanceNode) {
NewInstanceNode edgeTgt = (NewInstanceNode) addedTgt.getReplacement();
if (edgeTgt.makeP2Set().addAll(edgeSrc.getP2Set(), null)) {
for (Node element : pag.assignInstanceLookup(edgeTgt)) {
varNodeWorkList.add((VarNode) element);
if (element == src)
flush = false;
}
}
}
} else if (addedSrc instanceof AllocNode) {
VarNode edgeTgt = (VarNode) addedTgt.getReplacement();
if (edgeTgt.makeP2Set().add(addedSrc)) {
varNodeWorkList.add(edgeTgt);
if (edgeTgt == src)
flush = false;
}
} 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);
// We can only create alloc nodes for types that
// we know
edgeTgt.makeP2Set().add(pag.makeAllocNode(edgeSrc.getValue(), ccnType, ccn.getMethod()));
varNodeWorkList.add(edgeTgt);
}
}
});
if (edgeTgt.makeP2Set().add(addedSrc)) {
if (edgeTgt == src)
flush = false;
}
}
}
}
Node[] simpleTargets = pag.simpleLookup(src);
for (Node element : simpleTargets) {
if (element.makeP2Set().addAll(newP2Set, null)) {
varNodeWorkList.add((VarNode) element);
if (element == src)
flush = false;
ret = true;
}
}
Node[] storeTargets = pag.storeLookup(src);
for (Node element : storeTargets) {
final FieldRefNode fr = (FieldRefNode) element;
final SparkField f = fr.getField();
ret = fr.getBase().getP2Set().forall(new P2SetVisitor() {
public final void visit(Node n) {
AllocDotField nDotF = pag.makeAllocDotField((AllocNode) n, f);
if (nDotF.makeP2Set().addAll(newP2Set, null)) {
returnValue = true;
}
}
}) | ret;
}
final HashSet<Node[]> storesToPropagate = new HashSet<Node[]>();
final HashSet<Node[]> loadsToPropagate = new HashSet<Node[]>();
for (final FieldRefNode fr : src.getAllFieldRefs()) {
final SparkField field = fr.getField();
final Node[] storeSources = pag.storeInvLookup(fr);
if (storeSources.length > 0) {
newP2Set.forall(new P2SetVisitor() {
public final void visit(Node n) {
AllocDotField nDotF = pag.makeAllocDotField((AllocNode) n, field);
for (Node element : storeSources) {
Node[] pair = { element, nDotF.getReplacement() };
storesToPropagate.add(pair);
}
}
});
}
final Node[] loadTargets = pag.loadLookup(fr);
if (loadTargets.length > 0) {
newP2Set.forall(new P2SetVisitor() {
public final void visit(Node n) {
AllocDotField nDotF = pag.makeAllocDotField((AllocNode) n, field);
if (nDotF != null) {
for (Node element : loadTargets) {
Node[] pair = { nDotF.getReplacement(), element };
loadsToPropagate.add(pair);
}
}
}
});
}
}
if (flush)
src.getP2Set().flushNew();
for (Node[] p : storesToPropagate) {
VarNode storeSource = (VarNode) p[0];
AllocDotField nDotF = (AllocDotField) p[1];
if (nDotF.makeP2Set().addAll(storeSource.getP2Set(), null)) {
ret = true;
}
}
for (Node[] p : loadsToPropagate) {
AllocDotField nDotF = (AllocDotField) p[0];
VarNode loadTarget = (VarNode) p[1];
if (loadTarget.makeP2Set().addAll(nDotF.getP2Set(), null)) {
varNodeWorkList.add(loadTarget);
ret = true;
}
}
return ret;
}
use of soot.jimple.spark.pag.FieldRefNode in project soot by Sable.
the class MergeChecker method handleLoads.
protected void handleLoads(final FieldRefNode src) {
final Node[] loadTargets = pag.loadLookup(src);
PointsToSetInternal set = src.getP2Set();
if (set.isEmpty())
return;
for (Node element : loadTargets) {
VarNode target = (VarNode) element;
checkAll(target, set, src);
}
}
Aggregations