use of soot.jimple.spark.sets.PointsToSetInternal in project soot by Sable.
the class DemandCSPointsTo method dumpPathForLoc.
/*
* (non-Javadoc)
*
* @see AAA.summary.Refiner#dumpPathForBadLoc(soot.jimple.spark.pag.VarNode,
* soot.jimple.spark.pag.AllocNode)
*/
protected void dumpPathForLoc(VarNode v, final AllocNode badLoc, String filePrefix) {
final HashSet<VarNode> visited = new HashSet<VarNode>();
final DotPointerGraph dotGraph = new DotPointerGraph();
final class Helper {
boolean handle(VarNode curNode) {
assert curNode.getP2Set().contains(badLoc);
visited.add(curNode);
Node[] newEdges = pag.allocInvLookup(curNode);
for (int i = 0; i < newEdges.length; i++) {
AllocNode alloc = (AllocNode) newEdges[i];
if (alloc.equals(badLoc)) {
dotGraph.addNew(alloc, curNode);
return true;
}
}
for (AssignEdge assignEdge : csInfo.getAssignEdges(curNode)) {
VarNode other = assignEdge.getSrc();
if (other.getP2Set().contains(badLoc) && !visited.contains(other) && handle(other)) {
if (assignEdge.isCallEdge()) {
dotGraph.addCall(other, curNode, assignEdge.getCallSite());
} else {
dotGraph.addAssign(other, curNode);
}
return true;
}
}
Node[] loadEdges = pag.loadInvLookup(curNode);
for (int i = 0; i < loadEdges.length; i++) {
FieldRefNode frNode = (FieldRefNode) loadEdges[i];
SparkField field = frNode.getField();
VarNode base = frNode.getBase();
PointsToSetInternal baseP2Set = base.getP2Set();
for (Pair<VarNode, VarNode> store : fieldToStores.get(field)) {
if (store.getO2().getP2Set().hasNonEmptyIntersection(baseP2Set)) {
VarNode matchSrc = store.getO1();
if (matchSrc.getP2Set().contains(badLoc) && !visited.contains(matchSrc) && handle(matchSrc)) {
dotGraph.addMatch(matchSrc, curNode);
return true;
}
}
}
}
return false;
}
}
Helper h = new Helper();
h.handle(v);
// logger.debug(""+dotGraph.numEdges() + " edges on path");
dotGraph.dump("tmp/" + filePrefix + v.getNumber() + "_" + badLoc.getNumber() + ".dot");
}
use of soot.jimple.spark.sets.PointsToSetInternal 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.PointsToSetInternal 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.PointsToSetInternal 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.PointsToSetInternal in project soot by Sable.
the class SparkTransformer method findSetMass.
protected void findSetMass(PAG pag) {
int mass = 0;
int varMass = 0;
int adfs = 0;
int scalars = 0;
for (final VarNode v : pag.getVarNodeNumberer()) {
scalars++;
PointsToSetInternal set = v.getP2Set();
if (set != null)
mass += set.size();
if (set != null)
varMass += set.size();
}
for (final AllocNode an : pag.allocSources()) {
for (final AllocDotField adf : an.getFields()) {
PointsToSetInternal set = adf.getP2Set();
if (set != null)
mass += set.size();
if (set != null && set.size() > 0) {
adfs++;
}
}
}
logger.debug("Set mass: " + mass);
logger.debug("Variable mass: " + varMass);
logger.debug("Scalars: " + scalars);
logger.debug("adfs: " + adfs);
// Compute points-to set sizes of dereference sites BEFORE
// trimming sets by declared type
int[] deRefCounts = new int[30001];
for (VarNode v : pag.getDereferences()) {
PointsToSetInternal set = v.getP2Set();
int size = 0;
if (set != null)
size = set.size();
deRefCounts[size]++;
}
int total = 0;
for (int element : deRefCounts) total += element;
logger.debug("Dereference counts BEFORE trimming (total = " + total + "):");
for (int i = 0; i < deRefCounts.length; i++) {
if (deRefCounts[i] > 0) {
logger.debug("" + i + " " + deRefCounts[i] + " " + (deRefCounts[i] * 100.0 / total) + "%");
}
}
}
Aggregations