From db4be920e5f3f9785aae8508b2a68b84963531a7 Mon Sep 17 00:00:00 2001 From: sivaji Date: Tue, 22 May 2007 18:17:19 +0000 Subject: [PATCH] *Fixed duplicate edges in TaskGraph *Added 'isSourceNode' boolean var to FlagState to keep track of whether it's a start/source node. *Used 'FlagState.isSourceNode' to add Start Node in TaskGraph. --- .../Analysis/TaskStateAnalysis/FlagState.java | 17 ++++++ .../src/Analysis/TaskStateAnalysis/TEdge.java | 5 +- .../TaskStateAnalysis/TaskAnalysis.java | 3 + .../Analysis/TaskStateAnalysis/TaskGraph.java | 56 +++++++++++-------- .../Analysis/TaskStateAnalysis/TaskNode.java | 9 +++ 5 files changed, 66 insertions(+), 24 deletions(-) diff --git a/Robust/src/Analysis/TaskStateAnalysis/FlagState.java b/Robust/src/Analysis/TaskStateAnalysis/FlagState.java index 682333ff..b32c0265 100644 --- a/Robust/src/Analysis/TaskStateAnalysis/FlagState.java +++ b/Robust/src/Analysis/TaskStateAnalysis/FlagState.java @@ -21,6 +21,7 @@ public class FlagState extends GraphNode { private final HashSet flagstate; private final ClassDescriptor cd; private final Hashtable tags; + private boolean issourcenode; /** Class constructor * Creates a new flagstate with all flags set to false. @@ -31,6 +32,7 @@ public class FlagState extends GraphNode { this.cd=cd; this.tags=new Hashtable(); this.uid=FlagState.nodeid++; + this.issourcenode=false; } /** Class constructor @@ -44,6 +46,7 @@ public class FlagState extends GraphNode { this.cd=cd; this.tags=tags; this.uid=FlagState.nodeid++; + this.issourcenode=false; } @@ -54,6 +57,20 @@ public class FlagState extends GraphNode { public boolean get(FlagDescriptor fd) { return flagstate.contains(fd); } + + /** Checks if the flagstate is a source node. + * @return true if the flagstate is a sourcenode(i.e. Is the product of an allocation site). + */ + + public boolean isSourceNode(){ + return issourcenode; + } + + /** Sets the flagstate as a source node. + */ + public void setAsSourceNode(){ + issourcenode=true; + } public String toString() { diff --git a/Robust/src/Analysis/TaskStateAnalysis/TEdge.java b/Robust/src/Analysis/TaskStateAnalysis/TEdge.java index 96bdabe6..26e6ce47 100644 --- a/Robust/src/Analysis/TaskStateAnalysis/TEdge.java +++ b/Robust/src/Analysis/TaskStateAnalysis/TEdge.java @@ -9,13 +9,14 @@ import Util.Edge; public class TEdge extends Edge{ + public TEdge(TaskNode target){ super(target); } + - - + public int hashCode(){ return target.hashCode(); } diff --git a/Robust/src/Analysis/TaskStateAnalysis/TaskAnalysis.java b/Robust/src/Analysis/TaskStateAnalysis/TaskAnalysis.java index 0ac4a68a..7d98537a 100644 --- a/Robust/src/Analysis/TaskStateAnalysis/TaskAnalysis.java +++ b/Robust/src/Analysis/TaskStateAnalysis/TaskAnalysis.java @@ -28,6 +28,7 @@ public class TaskAnalysis { this.state=state; this.typeutil=new TypeUtil(state); this.taganalysis=taganalysis; + } /** Builds a table of flags for each class in the Bristlecone program. @@ -203,6 +204,8 @@ private void analyseTasks(FlagState fs) { Set newstates=taganalysis.getFlagStates(td); for(Iterator fsit=newstates.iterator();fsit.hasNext();) { FlagState fsnew=(FlagState) fsit.next(); + fsnew.setAsSourceNode(); + if (! ((Hashtable)flagstates.get(fsnew.getClassDescriptor())).containsKey(fsnew)) { ((Hashtable)flagstates.get(fsnew.getClassDescriptor())).put(fsnew, fsnew); toprocess.add(fsnew); diff --git a/Robust/src/Analysis/TaskStateAnalysis/TaskGraph.java b/Robust/src/Analysis/TaskStateAnalysis/TaskGraph.java index fbdcfcdd..00b31dc0 100644 --- a/Robust/src/Analysis/TaskStateAnalysis/TaskGraph.java +++ b/Robust/src/Analysis/TaskStateAnalysis/TaskGraph.java @@ -19,14 +19,15 @@ public class TaskGraph { for(Iterator classit=state.getClassSymbolTable().getDescriptorsIterator();classit.hasNext();) { ClassDescriptor cd=(ClassDescriptor) classit.next(); - produceTaskNodes(cd); + if (cd.hasFlags()) + produceTaskNodes(cd); } } public void createDOTfiles() { - for(Iterator classit=state.getClassSymbolTable().getDescriptorsIterator();classit.hasNext();) { - ClassDescriptor cd=(ClassDescriptor) classit.next(); + for(Iterator it_classes=(Iterator)cdtonodes.keys();it_classes.hasNext();) { + ClassDescriptor cd=(ClassDescriptor) it_classes.next(); Set tasknodes=getTaskNodes(cd); if (tasknodes!=null) { try { @@ -63,34 +64,45 @@ public class TaskGraph { Set fsnodes=taskanalysis.getFlagStates(cd); if (fsnodes==null) return; - + Hashtable tasknodes=new Hashtable(); cdtonodes.put(cd, tasknodes); for(Iterator it=fsnodes.iterator();it.hasNext();) { FlagState fs=(FlagState)it.next(); - Iterator it_inedges=fs.inedges(); - TaskNode tn; - do { - if (!fs.inedges().hasNext()){ - tn=new TaskNode("Start Node"); - } else { + TaskNode tn,sn; + + if (fs.isSourceNode()) { + sn=new TaskNode("Start Node"); + if(fs.edges().hasNext()){ + addEdges(fs,sn); + } + } + + while(it_inedges.hasNext()){ + FEdge inedge=(FEdge)it_inedges.next(); tn=new TaskNode(inedge.getLabel()); - } - if(fs.edges().hasNext()){ - tn=(TaskNode)canonicalizeTaskNode(tasknodes, tn); - for (Iterator it_edges=fs.edges();it_edges.hasNext();){ - TaskNode target=new TaskNode(((FEdge)it_edges.next()).getLabel()); - target=(TaskNode)canonicalizeTaskNode(tasknodes,target); - TEdge tedge=new TEdge(target); - // if (!tn.edges.contains(tedge)) - tn.addEdge(new TEdge(target)); - } - } - } while(it_inedges.hasNext()); + if(fs.edges().hasNext()){ + addEdges(fs,tn); + } + } } } + private void addEdges(FlagState fs, TaskNode tn){ + + Hashtable tasknodes=(Hashtable)cdtonodes.get(fs.getClassDescriptor()); + tn=(TaskNode)canonicalizeTaskNode(tasknodes, tn); + for (Iterator it_edges=fs.edges();it_edges.hasNext();){ + TaskNode target=new TaskNode(((FEdge)it_edges.next()).getLabel()); + target=(TaskNode)canonicalizeTaskNode(tasknodes,target); + + TEdge newedge=new TEdge(target); + if (! tn.edgeExists(newedge)) + tn.addEdge(new TEdge(target)); + } + + } } diff --git a/Robust/src/Analysis/TaskStateAnalysis/TaskNode.java b/Robust/src/Analysis/TaskStateAnalysis/TaskNode.java index 2d5eec35..e2dbd34e 100644 --- a/Robust/src/Analysis/TaskStateAnalysis/TaskNode.java +++ b/Robust/src/Analysis/TaskStateAnalysis/TaskNode.java @@ -53,6 +53,15 @@ public class TaskNode extends GraphNode { } return false; } + + public boolean edgeExists(TEdge newedge){ + if(edges.isEmpty()) + return false; + else + return edges.contains(newedge); + } + + } -- 2.34.1