package Analysis.Disjoint;
+import IR.Flat.FlatNew;
public interface Alloc {
-
+ public FlatNew getFlatNew();
public String toStringBrief();
+ public int getUniqueAllocSiteID();
}
\ No newline at end of file
// are Canonical, but specifically so an AllocSite can
// be an operand to a CanonicalOp
-public class AllocSite extends Canonical {
+public class AllocSite extends Canonical implements Alloc {
static protected int uniqueIDcount = 0;
public static final int strongupdate = 3;
// identify an allocation site of affected object
- protected AllocSite affectedAllocSite;
+ protected Alloc affectedAllocSite;
// identify operation type
protected int type;
// identify a field
protected FieldDescriptor field;
- public Effect(AllocSite affectedAS, int type, FieldDescriptor field) {
+ public Effect(Alloc affectedAS, int type, FieldDescriptor field) {
this.affectedAllocSite = affectedAS;
this.type = type;
this.field = field;
}
- public AllocSite getAffectedAllocSite() {
+ public Alloc getAffectedAllocSite() {
return affectedAllocSite;
}
- public void setAffectedAllocSite(AllocSite affectedAllocSite) {
+ public void setAffectedAllocSite(Alloc affectedAllocSite) {
this.affectedAllocSite = affectedAllocSite;
}
import IR.*;
import IR.Flat.*;
+import Analysis.Pointer.Edge;
/////////////////////////////////////////////
//
}
}
+ public void analyzeFlatFieldNode(Set<Edge> sources, FieldDescriptor fld, FlatNode currentProgramPoint) {
+ for (Edge edge:sources) {
+ TaintSet taintSet = edge.getTaints();
+ Alloc affectedAlloc = edge.getDst();
+ Effect effect = new Effect(affectedAlloc, Effect.read, fld);
+
+ for (Iterator<Taint> taintSetIter = taintSet.iterator(); taintSetIter.hasNext();) {
+ Taint taint = taintSetIter.next();
+ add(taint, effect, currentProgramPoint);
+ }
+ }
+ }
+
public void analyzeFlatSetFieldNode(ReachGraph rg, TempDescriptor lhs, FieldDescriptor fld, FlatNode currentProgramPoint, boolean strongUpdate) {
VariableNode vn = rg.td2vn.get(lhs);
}
+ public void analyzeFlatSetFieldNode(Set<Edge> dstedges, FieldDescriptor fld, FlatNode currentProgramPoint) {
+
+ for (Edge edge:dstedges) {
+ TaintSet taintSet = edge.getTaints();
+ Alloc affectedAlloc = edge.getDst();
+ Effect effect = new Effect(affectedAlloc, Effect.write, fld);
+ for (Iterator<Taint> taintSetIter = taintSet.iterator(); taintSetIter.hasNext();) {
+ Taint taint = taintSetIter.next();
+ add( taint, effect, currentProgramPoint );
+ }
+ }
+ }
+
+
public String toString() {
return taint2effects.toString();
}
package Analysis.Pointer;
+import Analysis.Disjoint.Alloc;
import java.util.*;
import IR.*;
import IR.Flat.*;
public class AllocFactory {
- public static class AllocNode {
+ public static class AllocNode implements Alloc {
int allocsite;
boolean summary;
- TypeDescriptor type;
+ FlatNew node;
- public AllocNode(int allocsite, TypeDescriptor type, boolean summary) {
+ public AllocNode(int allocsite, FlatNew node, boolean summary) {
this.allocsite=allocsite;
this.summary=summary;
- this.type=type;
+ this.node=node;
}
public TypeDescriptor getType() {
- return type;
+ return node.getType();
+ }
+
+ public FlatNew getFlatNew() {
+ return node;
+ }
+
+ public int getUniqueAllocSiteID() {
+ return allocsite;
}
public boolean isSummary() {
return false;
}
+ public String toStringBrief() {
+ return getID();
+ }
+
public String toString() {
return getID();
}
ClassDescriptor stringcd=typeUtil.getClass(TypeUtil.StringClass);
TypeDescriptor stringtd=new TypeDescriptor(stringcd);
TypeDescriptor stringarraytd=stringtd.makeArray(state);
- StringArray=new AllocNode(0, stringarraytd, false);
- Strings=new AllocNode(1, stringtd, true);
+ StringArray=new AllocNode(0, new FlatNew(stringarraytd, null, false), false);
+ Strings=new AllocNode(1, new FlatNew(stringtd, null, false), true);
}
public int getSiteNumber(FlatNew node) {
public AllocNode getAllocNode(FlatNew node, boolean isSummary) {
int site=getSiteNumber(node);
- AllocNode key=new AllocNode(site, node.getType(), isSummary);
+ AllocNode key=new AllocNode(site, node, isSummary);
if (!allocNodeMap.containsKey(key)) {
allocNodeMap.put(key, key);
return key;
public AllocNode getAllocNode(AllocNode node, boolean isSummary) {
int site=node.allocsite;
- AllocNode key=new AllocNode(site, node.getType(), isSummary);
+ AllocNode key=new AllocNode(site, node.node, isSummary);
if (!allocNodeMap.containsKey(key)) {
allocNodeMap.put(key, key);
return key;
this.dst=dst;
}
+ public AllocNode getDst() {
+ return dst;
+ }
+
public int hashCode() {
int hashcode=dst.hashCode();
if (fd!=null) {
return edgeset;
}
+ static MySet<Edge> genEdges(MySet<Edge> srcSet, FieldDescriptor fd, MySet<Edge> dstSet) {
+ MySet<Edge> edgeset=new MySet<Edge>();
+ for(Edge srcedge:srcSet) {
+ for(Edge dstedge:dstSet) {
+ edgeset.add(dstedge.changeSrc(fd, srcedge.dst));
+ }
+ }
+ return edgeset;
+ }
+
static MySet<Edge> genEdges(HashSet<AllocNode> srcSet, FieldDescriptor fd, MySet<Edge> dstSet) {
MySet<Edge> edgeset=new MySet<Edge>();
for(AllocNode srcnode:srcSet) {
return edges;
}
+ static MySet<Edge> getEdges(Graph graph, Delta delta, MySet<Edge> srcNodes, FieldDescriptor fd) {
+ MySet<Edge> nodes=new MySet<Edge>();
+ for(Edge node:srcNodes) {
+ MySet<Edge> removeedges=delta.heapedgeremove.get(node.dst);
+ for(Edge e:graph.getEdges(node.dst)) {
+ if (e.fd==fd&&(removeedges==null||!removeedges.contains(e)))
+ nodes.add(e);
+ }
+ if (delta.heapedgeadd.containsKey(node.dst))
+ for(Edge e:delta.heapedgeadd.get(node.dst)) {
+ if (e.fd==fd)
+ nodes.add(e);
+ }
+ }
+ return nodes;
+ }
+
static MySet<Edge> getEdges(Graph graph, Delta delta, HashSet<AllocNode> srcNodes, FieldDescriptor fd) {
MySet<Edge> nodes=new MySet<Edge>();
for(AllocNode node:srcNodes) {
return newedges;
}
-
static MySet<Edge> getDiffEdges(Delta delta, HashSet<AllocNode> srcNodes, FieldDescriptor fd) {
MySet<Edge> newedges=new MySet<Edge>();
for(Map.Entry<AllocNode, MySet<Edge>> entry:delta.baseheapedge.entrySet()) {
import Analysis.Disjoint.Canonical;
import Analysis.CallGraph.CallGraph;
import Analysis.OoOJava.RBlockRelationAnalysis;
+import Analysis.Disjoint.EffectsAnalysis;
+import Analysis.Disjoint.BuildStateMachines;
import java.io.*;
LinkedList<Delta> toprocess;
TempDescriptor returntmp;
RBlockRelationAnalysis taskAnalysis;
+ EffectsAnalysis effectsAnalysis;
+ BuildStateMachines buildStateMachines;
public Pointer(State state, TypeUtil typeUtil, CallGraph callGraph, RBlockRelationAnalysis taskAnalysis) {
this(state, typeUtil);
this.callGraph=callGraph;
this.OoOJava=true;
this.taskAnalysis=taskAnalysis;
+ this.effectsAnalysis=new EffectsAnalysis();
+ effectsAnalysis.state=state;
+ effectsAnalysis.buildStateMachines=new BuildStateMachines();
}
public Pointer(State state, TypeUtil typeUtil) {
if (delta.getInit()) {
MySet<Edge> srcEdges=GraphManip.getEdges(graph, delta, src);
- HashSet<AllocNode> dstNodes=GraphManip.getNodes(graph, delta, dst);
- MySet<Edge> edgesToAdd=GraphManip.genEdges(dstNodes, fd, srcEdges);
+ MySet<Edge> dstEdges=GraphManip.getEdges(graph, delta, dst);
+ MySet<Edge> edgesToAdd=GraphManip.genEdges(dstEdges, fd, srcEdges);
MySet<Edge> edgesToRemove=null;
- if (dstNodes.size()==1&&!dstNodes.iterator().next().isSummary()&&fd!=null) {
+ if (dstEdges.size()==1&&!dstEdges.iterator().next().dst.isSummary()&&fd!=null) {
/* Can do a strong update */
- edgesToRemove=GraphManip.getEdges(graph, delta, dstNodes, fd);
+ edgesToRemove=GraphManip.getEdges(graph, delta, dstEdges, fd);
graph.strongUpdateSet=edgesToRemove;
} else
graph.strongUpdateSet=new MySet<Edge>();
+
+ if (OoOJava) {
+ effectsAnalysis.analyzeFlatSetFieldNode(dstEdges, fd, node);
+ }
+
/* Update diff */
updateHeapDelta(graph, delta, edgesToAdd, edgesToRemove);
applyDiffs(graph, delta);
MySet<Edge> newSrcEdges=GraphManip.getDiffEdges(delta, src);
MySet<Edge> srcEdges=GraphManip.getEdges(graph, delta, src);
HashSet<AllocNode> dstNodes=GraphManip.getNodes(graph, delta, dst);
- HashSet<AllocNode> newDstNodes=GraphManip.getDiffNodes(delta, dst);
+ MySet<Edge> newDstEdges=GraphManip.getDiffEdges(delta, dst);
+ if (OoOJava) {
+ effectsAnalysis.analyzeFlatSetFieldNode(newDstEdges, fd, node);
+ }
MySet<Edge> edgesToRemove=null;
- if (newDstNodes.size()!=0) {
+ if (newDstEdges.size()!=0) {
if (dstNodes.size()>1&&!dstNodes.iterator().next().isSummary()&&fd!=null) {
/* Need to undo strong update */
if (graph.strongUpdateSet!=null) {
edgesToAdd.addAll(graph.strongUpdateSet);
graph.strongUpdateSet=null; //Prevent future strong updates
}
- } else if (dstNodes.size()==1&&newDstNodes.size()==1&&!newDstNodes.iterator().next().isSummary()&&graph.strongUpdateSet!=null&&fd!=null) {
+ } else if (dstNodes.size()==1&&newDstEdges.size()==1&&!newDstEdges.iterator().next().dst.isSummary()&&graph.strongUpdateSet!=null&&fd!=null) {
edgesToRemove=GraphManip.getEdges(graph, delta, dstNodes, fd);
graph.strongUpdateSet.addAll(edgesToRemove);
}
- Edge.mergeEdgesInto(edgesToAdd, GraphManip.genEdges(newDstNodes, fd, srcEdges));
+ Edge.mergeEdgesInto(edgesToAdd, GraphManip.genEdges(newDstEdges, fd, srcEdges));
}
//Kill new edges
MySet<Edge> srcedges=GraphManip.getEdges(graph, delta, src);
MySet<Edge> edgesToAdd=GraphManip.dereference(graph, delta, dst, srcedges, fd, node, taint);
MySet<Edge> edgesToRemove=GraphManip.getEdges(graph, delta, dst);
+ if (OoOJava)
+ effectsAnalysis.analyzeFlatFieldNode(srcedges, fd, node);
+
updateVarDelta(graph, delta, dst, edgesToAdd, edgesToRemove);
applyDiffs(graph, delta);
} else {
/* Compute set of edges to remove */
MySet<Edge> edgesToRemove=GraphManip.getDiffEdges(delta, dst);
+ if (OoOJava)
+ effectsAnalysis.analyzeFlatFieldNode(newsrcedges, fd, node);
+
/* Update diff */
updateVarDelta(graph, delta, dst, edgesToAdd, edgesToRemove);
applyDiffs(graph, delta);
}
+
return delta;
}