use of soot.jimple.spark.pag.LocalVarNode in project soot by Sable.
the class SootUtil method buildStoreMap.
public static FieldAccessMap buildStoreMap(PAG pag) {
FieldAccessMap ret = new FieldAccessMap();
Iterator frNodeIter = pag.storeInvSourcesIterator();
while (frNodeIter.hasNext()) {
FieldRefNode frNode = (FieldRefNode) frNodeIter.next();
SparkField field = frNode.getField();
Node[] targets = pag.storeInvLookup(frNode);
for (int i = 0; i < targets.length; i++) {
VarNode target = (VarNode) targets[i];
if (target instanceof GlobalVarNode)
continue;
ret.put(field, new Pair<FieldRefNode, LocalVarNode>(frNode, (LocalVarNode) target));
}
}
return ret;
}
use of soot.jimple.spark.pag.LocalVarNode in project soot by Sable.
the class GeomPointsTo method getMethodIDFromPtr.
/**
* Get the index of the enclosing function of the specified node.
*/
public int getMethodIDFromPtr(IVarAbstraction pn) {
SootMethod sm = null;
int ret = Constants.SUPER_MAIN;
Node node = pn.getWrappedNode();
if (node instanceof AllocNode) {
sm = ((AllocNode) node).getMethod();
} else if (node instanceof LocalVarNode) {
sm = ((LocalVarNode) node).getMethod();
} else if (node instanceof AllocDotField) {
sm = ((AllocDotField) node).getBase().getMethod();
}
if (sm != null && func2int.containsKey(sm)) {
int id = func2int.get(sm);
if (vis_cg[id] == 0)
ret = Constants.UNKNOWN_FUNCTION;
else
ret = id;
}
return ret;
}
use of soot.jimple.spark.pag.LocalVarNode in project soot by Sable.
the class HeapInsNode method do_before_propagation.
@Override
public void do_before_propagation() {
// if ( complex_cons == null )
do_pts_interval_merge();
// if ( !(me instanceof LocalVarNode) )
do_flow_edge_interval_merge();
// This pointer filter, please read the comments at this line in file FullSensitiveNode.java
Node wrappedNode = getWrappedNode();
if (wrappedNode instanceof LocalVarNode && ((LocalVarNode) wrappedNode).isThisPtr()) {
SootMethod func = ((LocalVarNode) wrappedNode).getMethod();
if (!func.isConstructor()) {
// We don't process the specialinvoke call edge
SootClass defClass = func.getDeclaringClass();
Hierarchy typeHierarchy = Scene.v().getActiveHierarchy();
for (Iterator<AllocNode> it = new_pts.keySet().iterator(); it.hasNext(); ) {
AllocNode obj = it.next();
if (obj.getType() instanceof RefType) {
SootClass sc = ((RefType) obj.getType()).getSootClass();
if (defClass != sc) {
try {
SootMethod rt_func = typeHierarchy.resolveConcreteDispatch(sc, func);
if (rt_func != func) {
it.remove();
// Also preclude it from propagation again
pt_objs.put(obj, (HeapInsIntervalManager) deadManager);
}
} catch (RuntimeException e) {
// If the input program has a wrong type cast, resolveConcreteDispatch fails and it goes here
// We simply ignore this error
}
}
}
}
}
}
}
use of soot.jimple.spark.pag.LocalVarNode in project soot by Sable.
the class EvalResults method checkAliasAnalysis.
/**
* Count how many aliased base pointers appeared in all user's functions.
*/
public void checkAliasAnalysis() {
Set<IVarAbstraction> access_expr = new HashSet<IVarAbstraction>();
ArrayList<IVarAbstraction> al = new ArrayList<IVarAbstraction>();
Value[] values = new Value[2];
for (SootMethod sm : ptsProvider.getAllReachableMethods()) {
if (sm.isJavaLibraryMethod())
continue;
if (!sm.isConcrete())
continue;
if (!sm.hasActiveBody()) {
sm.retrieveActiveBody();
}
if (!ptsProvider.isValidMethod(sm))
continue;
// access_expr.clear();
for (Iterator<Unit> stmts = sm.getActiveBody().getUnits().iterator(); stmts.hasNext(); ) {
Stmt st = (Stmt) stmts.next();
if (st instanceof AssignStmt) {
AssignStmt a = (AssignStmt) st;
values[0] = a.getLeftOp();
values[1] = a.getRightOp();
for (Value v : values) {
// expression: p.f
if (v instanceof InstanceFieldRef) {
InstanceFieldRef ifr = (InstanceFieldRef) v;
final SootField field = ifr.getField();
if (!(field.getType() instanceof RefType))
continue;
LocalVarNode vn = ptsProvider.findLocalVarNode((Local) ifr.getBase());
if (vn == null)
continue;
if (ptsProvider.isExceptionPointer(vn))
continue;
IVarAbstraction pn = ptsProvider.findInternalNode(vn);
if (pn == null)
continue;
pn = pn.getRepresentative();
if (pn.hasPTResult())
access_expr.add(pn);
}
}
}
}
}
access_expr.remove(null);
al.addAll(access_expr);
access_expr = null;
// Next, we pair up all the pointers
Date begin = new Date();
int size = al.size();
for (int i = 0; i < size; ++i) {
IVarAbstraction pn = al.get(i);
VarNode n1 = (VarNode) pn.getWrappedNode();
for (int j = i + 1; j < size; ++j) {
IVarAbstraction qn = al.get(j);
VarNode n2 = (VarNode) qn.getWrappedNode();
if (pn.heap_sensitive_intersection(qn))
evalRes.n_hs_alias++;
// We directly use the SPARK points-to sets
if (n1.getP2Set().hasNonEmptyIntersection(n2.getP2Set()))
evalRes.n_hi_alias++;
}
}
evalRes.n_alias_pairs = size * (size - 1) / 2;
Date end = new Date();
ptsProvider.ps.println();
ptsProvider.ps.println("--------> Alias Pairs Evaluation <---------");
ptsProvider.ps.println("Number of pointer pairs in app code: " + evalRes.n_alias_pairs);
ptsProvider.ps.printf("Heap sensitive alias pairs (by Geom): %d, Percentage = %.3f%%\n", evalRes.n_hs_alias, (double) evalRes.n_hs_alias / evalRes.n_alias_pairs * 100);
ptsProvider.ps.printf("Heap insensitive alias pairs (by SPARK): %d, Percentage = %.3f%%\n", evalRes.n_hi_alias, (double) evalRes.n_hi_alias / evalRes.n_alias_pairs * 100);
ptsProvider.ps.printf("Using time: %dms \n", end.getTime() - begin.getTime());
ptsProvider.ps.println();
}
use of soot.jimple.spark.pag.LocalVarNode in project soot by Sable.
the class EvalResults method estimateHeapDefuseGraph.
/**
* Estimate the size of the def-use graph for the heap memory. The heap
* graph is estimated without context information.
*/
public void estimateHeapDefuseGraph() {
final Map<IVarAbstraction, int[]> defUseCounterForGeom = new HashMap<IVarAbstraction, int[]>();
final Map<AllocDotField, int[]> defUseCounterForSpark = new HashMap<AllocDotField, int[]>();
Date begin = new Date();
for (SootMethod sm : ptsProvider.getAllReachableMethods()) {
if (sm.isJavaLibraryMethod())
continue;
if (!sm.isConcrete())
continue;
if (!sm.hasActiveBody()) {
sm.retrieveActiveBody();
}
if (!ptsProvider.isValidMethod(sm))
continue;
// We first gather all the memory access expressions
for (Iterator<Unit> stmts = sm.getActiveBody().getUnits().iterator(); stmts.hasNext(); ) {
Stmt st = (Stmt) stmts.next();
if (!(st instanceof AssignStmt))
continue;
AssignStmt a = (AssignStmt) st;
final Value lValue = a.getLeftOp();
final Value rValue = a.getRightOp();
InstanceFieldRef ifr = null;
if (lValue instanceof InstanceFieldRef) {
// Def statement
ifr = (InstanceFieldRef) lValue;
} else if (rValue instanceof InstanceFieldRef) {
// Use statement
ifr = (InstanceFieldRef) rValue;
}
if (ifr != null) {
final SootField field = ifr.getField();
LocalVarNode vn = ptsProvider.findLocalVarNode((Local) ifr.getBase());
if (vn == null)
continue;
IVarAbstraction pn = ptsProvider.findInternalNode(vn);
if (pn == null)
continue;
pn = pn.getRepresentative();
if (!pn.hasPTResult())
continue;
// Spark
vn.getP2Set().forall(new P2SetVisitor() {
@Override
public void visit(Node n) {
IVarAbstraction padf = ptsProvider.findAndInsertInstanceField((AllocNode) n, field);
AllocDotField adf = (AllocDotField) padf.getWrappedNode();
int[] defUseUnit = defUseCounterForSpark.get(adf);
if (defUseUnit == null) {
defUseUnit = new int[2];
defUseCounterForSpark.put(adf, defUseUnit);
}
if (lValue instanceof InstanceFieldRef) {
defUseUnit[0]++;
} else {
defUseUnit[1]++;
}
}
});
// Geom
Set<AllocNode> objsSet = pn.get_all_points_to_objects();
for (AllocNode obj : objsSet) {
/*
* We will create a lot of instance fields. Because in
* points-to analysis, we concern only the reference
* type fields. But here, we concern all the fields read
* write including the primitive type fields.
*/
IVarAbstraction padf = ptsProvider.findAndInsertInstanceField(obj, field);
int[] defUseUnit = defUseCounterForGeom.get(padf);
if (defUseUnit == null) {
defUseUnit = new int[2];
defUseCounterForGeom.put(padf, defUseUnit);
}
if (lValue instanceof InstanceFieldRef) {
defUseUnit[0]++;
} else {
defUseUnit[1]++;
}
}
}
}
}
for (int[] defUseUnit : defUseCounterForSpark.values()) {
evalRes.n_spark_du_pairs += ((long) defUseUnit[0]) * defUseUnit[1];
}
for (int[] defUseUnit : defUseCounterForGeom.values()) {
evalRes.n_geom_du_pairs += ((long) defUseUnit[0]) * defUseUnit[1];
}
Date end = new Date();
ptsProvider.ps.println();
ptsProvider.ps.println("-----------> Heap Def Use Graph Evaluation <------------");
ptsProvider.ps.println("The edges in the heap def-use graph is (by Geom): " + evalRes.n_geom_du_pairs);
ptsProvider.ps.println("The edges in the heap def-use graph is (by Spark): " + evalRes.n_spark_du_pairs);
ptsProvider.ps.printf("Using time: %dms \n", end.getTime() - begin.getTime());
ptsProvider.ps.println();
}
Aggregations