From b4dcf05f9bd8d277bcdf3dbe87f7894dcd920bbc Mon Sep 17 00:00:00 2001 From: bdemsky Date: Wed, 2 Mar 2011 22:53:45 +0000 Subject: [PATCH] code cleanup --- Robust/src/Analysis/Pointer/Pointer.java | 187 ++++++++++------------- 1 file changed, 77 insertions(+), 110 deletions(-) diff --git a/Robust/src/Analysis/Pointer/Pointer.java b/Robust/src/Analysis/Pointer/Pointer.java index aaa3e207..aae36b2c 100644 --- a/Robust/src/Analysis/Pointer/Pointer.java +++ b/Robust/src/Analysis/Pointer/Pointer.java @@ -211,80 +211,100 @@ public class Pointer { } } - Delta processFlatCall(BBlock callblock, int callindex, FlatCall fcall, Delta delta, Graph graph) { - Delta newDelta=new Delta(null, false); - if (delta.getInit()) { - MySet edgeset=new MySet(); - HashSet nodeset=new HashSet(); - HashSet targetSet=new HashSet(); - Stack tovisit=new Stack(); - TempDescriptor tmpthis=fcall.getThis(); - - //Handle the this temp - if (tmpthis!=null) { - MySet edges=GraphManip.getEdges(graph, delta, tmpthis); - newDelta.varedgeadd.put(tmpthis, (MySet) edges.clone()); - edgeset.addAll(edges); - for(Edge e:edges) { - AllocNode dstnode=e.dst; - if (!nodeset.contains(dstnode)) { - TypeDescriptor type=dstnode.getType(); - if (!type.isArray()) { - targetSet.add(type.getClassDesc()); - } else { - //arrays don't have code - targetSet.add(typeUtil.getClass(TypeUtil.ObjectClass)); - } - nodeset.add(dstnode); - tovisit.add(dstnode); + void processThisTargets(HashSet targetSet, Graph graph, Delta delta, Delta newDelta, HashSet nodeset, Stack tovisit, MySet edgeset, TempDescriptor tmpthis, HashSet oldnodeset) { + //Handle the this temp + if (tmpthis!=null) { + MySet edges=(oldnodeset!=null)?GraphManip.getDiffEdges(delta, tmpthis):GraphManip.getEdges(graph, delta, tmpthis); + newDelta.varedgeadd.put(tmpthis, (MySet) edges.clone()); + edgeset.addAll(edges); + for(Edge e:edges) { + AllocNode dstnode=e.dst; + if (!nodeset.contains(dstnode)&&(oldnodeset==null||!oldnodeset.contains(dstnode))) { + TypeDescriptor type=dstnode.getType(); + if (!type.isArray()) { + targetSet.add(type.getClassDesc()); + } else { + //arrays don't have code + targetSet.add(typeUtil.getClass(TypeUtil.ObjectClass)); } + nodeset.add(dstnode); + tovisit.add(dstnode); } } + } + } - //Go through each temp - for(int i=0;i edges=GraphManip.getEdges(graph, delta, tmp); - newDelta.varedgeadd.put(tmp, (MySet) edges.clone()); - edgeset.addAll(edges); - for(Edge e:edges) { - if (!nodeset.contains(e.dst)) { - nodeset.add(e.dst); - tovisit.add(e.dst); - } + void processParams(Graph graph, Delta delta, Delta newDelta, HashSet nodeset, Stack tovisit, MySet edgeset, FlatCall fcall, boolean diff) { + //Go through each temp + for(int i=0;i edges=diff?GraphManip.getDiffEdges(delta, tmp):GraphManip.getEdges(graph, delta, tmp); + newDelta.varedgeadd.put(tmp, (MySet) edges.clone()); + edgeset.addAll(edges); + for(Edge e:edges) { + if (!nodeset.contains(e.dst)) { + nodeset.add(e.dst); + tovisit.add(e.dst); } } - - //Traverse all reachable nodes + } + } + + void computeReachableNodes(Graph graph, Delta delta, Delta newDelta, HashSet nodeset, Stack tovisit, MySet edgeset, HashSet oldnodeset) { while(!tovisit.isEmpty()) { AllocNode node=tovisit.pop(); MySet edges=GraphManip.getEdges(graph, delta, node); newDelta.heapedgeadd.put(node, edges); edgeset.addAll(edges); for(Edge e:edges) { - if (!nodeset.contains(e.dst)) { + if (!nodeset.contains(e.dst)&&(oldnodeset==null||!oldnodeset.contains(e.dst))) { nodeset.add(e.dst); tovisit.add(e.dst); } } } + } - //Compute call targets - MethodDescriptor md=fcall.getMethod(); - HashSet targets=new HashSet(); - if (md.isStatic()) { - targets.add(md); - } else { - //Compute Edges - for(Edge e:newDelta.varedgeadd.get(tmpthis)) { - AllocNode node=e.dst; - ClassDescriptor cd=node.getType().getClassDesc(); - //Figure out exact method called and add to set - targets.add(cd.getCalledMethod(md)); - } + HashSet computeTargets(FlatCall fcall, Delta newDelta) { + TempDescriptor tmpthis=fcall.getThis(); + MethodDescriptor md=fcall.getMethod(); + HashSet targets=new HashSet(); + if (md.isStatic()) { + targets.add(md); + } else { + //Compute Edges + for(Edge e:newDelta.varedgeadd.get(tmpthis)) { + AllocNode node=e.dst; + ClassDescriptor cd=node.getType().getClassDesc(); + //Figure out exact method called and add to set + targets.add(cd.getCalledMethod(md)); } + } + return targets; + } + Delta processFlatCall(BBlock callblock, int callindex, FlatCall fcall, Delta delta, Graph graph) { + Delta newDelta=new Delta(null, false); + + if (delta.getInit()) { + MySet edgeset=new MySet(); + HashSet nodeset=new HashSet(); + HashSet targetSet=new HashSet(); + Stack tovisit=new Stack(); + TempDescriptor tmpthis=fcall.getThis(); + + //Handle the this temp + processThisTargets(targetSet, graph, delta, newDelta, nodeset, tovisit, edgeset, tmpthis, null); + + //Go through each temp + processParams(graph, delta, newDelta, nodeset, tovisit, edgeset, fcall, false); + + //Traverse all reachable nodes + computeReachableNodes(graph, delta, newDelta, nodeset, tovisit, edgeset, null); + + //Compute call targets + HashSet targets=computeTargets(fcall, newDelta); //Fix mapping for(MethodDescriptor calledmd:targets) { @@ -355,39 +375,10 @@ public class Pointer { TempDescriptor tmpthis=fcall.getThis(); //Handle the this temp - if (tmpthis!=null) { - MySet edges=GraphManip.getDiffEdges(delta, tmpthis); - newDelta.varedgeadd.put(tmpthis, (MySet) edges.clone()); - edgeset.addAll(edges); - for(Edge e:edges) { - AllocNode dstnode=e.dst; - if (!nodeset.contains(dstnode)&&!oldnodeset.contains(dstnode)) { - TypeDescriptor type=dstnode.getType(); - if (!type.isArray()) { - targetSet.add(type.getClassDesc()); - } else { - //arrays don't have code - targetSet.add(typeUtil.getClass(TypeUtil.ObjectClass)); - } - nodeset.add(dstnode); - tovisit.add(dstnode); - } - } - } + processThisTargets(targetSet, graph, delta, newDelta, nodeset, tovisit, edgeset, tmpthis, oldnodeset); //Go through each temp - for(int i=0;i edges=GraphManip.getDiffEdges(delta, tmp); - newDelta.varedgeadd.put(tmp, (MySet) edges.clone()); - edgeset.addAll(edges); - for(Edge e:edges) { - if (!nodeset.contains(e.dst)&&!oldnodeset.contains(e.dst)) { - nodeset.add(e.dst); - tovisit.add(e.dst); - } - } - } + processParams(graph, delta, newDelta, nodeset, tovisit, edgeset, fcall, true); //Go through each new heap edge that starts from old node MySet newedges=GraphManip.getDiffEdges(delta, oldnodeset); @@ -400,34 +391,10 @@ public class Pointer { } //Traverse all reachable nodes - while(!tovisit.isEmpty()) { - AllocNode node=tovisit.pop(); - MySet edges=GraphManip.getEdges(graph, delta, node); - - newDelta.heapedgeadd.put(node, edges); - edgeset.addAll(edges); - for(Edge e:edges) { - if (!nodeset.contains(e.dst)&&!oldnodeset.contains(e.dst)) { - nodeset.add(e.dst); - tovisit.add(e.dst); - } - } - } + computeReachableNodes(graph, delta, newDelta, nodeset, tovisit, edgeset, oldnodeset); //Compute call targets - MethodDescriptor md=fcall.getMethod(); - HashSet targets=new HashSet(); - if (md.isStatic()) { - targets.add(md); - } else { - //Compute Edges - for(Edge e:newDelta.varedgeadd.get(tmpthis)) { - AllocNode node=e.dst; - ClassDescriptor cd=node.getType().getClassDesc(); - //Figure out exact method called and add to set - targets.add(cd.getCalledMethod(md)); - } - } + HashSet targets=computeTargets(fcall, newDelta); //add in new nodeset and edgeset oldnodeset.addAll(nodeset); -- 2.34.1