From 0091b84d8649d93060656cfbbd99b6183c9a05f9 Mon Sep 17 00:00:00 2001 From: sivaji Date: Fri, 8 Jun 2007 08:25:36 +0000 Subject: [PATCH] *Added the program flow feature. --- .../Analysis/TaskStateAnalysis/TaskGraph.java | 90 +++++++++++++++++-- Robust/src/Interface/WebInterface.java | 61 ++++++++++--- Robust/src/Util/Edge.java | 2 +- 3 files changed, 137 insertions(+), 16 deletions(-) diff --git a/Robust/src/Analysis/TaskStateAnalysis/TaskGraph.java b/Robust/src/Analysis/TaskStateAnalysis/TaskGraph.java index f92df9cb..013bfab8 100644 --- a/Robust/src/Analysis/TaskStateAnalysis/TaskGraph.java +++ b/Robust/src/Analysis/TaskStateAnalysis/TaskGraph.java @@ -3,6 +3,7 @@ import java.util.*; import IR.State; import IR.SymbolTable; import IR.ClassDescriptor; +import IR.TaskDescriptor; import java.io.File; import java.io.FileWriter; import java.io.FileOutputStream; @@ -12,17 +13,23 @@ public class TaskGraph { State state; Hashtable cdtonodes; Hashtable nodes; + Hashtable alltasknodes; + + //Colors + String colors[]={"red","blue","green","brown","orange","pink","black","brown","grey","olivedrab"}; public TaskGraph(State state, TaskAnalysis taskanalysis) { this.state=state; this.taskanalysis=taskanalysis; this.cdtonodes=new Hashtable(); + this.alltasknodes=new Hashtable(); for(Iterator classit=state.getClassSymbolTable().getDescriptorsIterator();classit.hasNext();) { ClassDescriptor cd=(ClassDescriptor) classit.next(); if (cd.hasFlags()) produceTaskNodes(cd); } + produceAllTaskNodes(); } @@ -77,7 +84,7 @@ public class TaskGraph { if (fs.isSourceNode()) { sn=new TaskNode("Start Node"); if(fs.edges().hasNext()){ - addEdges(fs,sn); + addEdges(fs,sn,tasknodes); } } @@ -86,12 +93,71 @@ public class TaskGraph { FEdge inedge=(FEdge)it_inedges.next(); tn=new TaskNode(inedge.getLabel()); if(fs.edges().hasNext()){ - addEdges(fs,tn); + addEdges(fs,tn,tasknodes); } } } } + private void produceAllTaskNodes(){ + alltasknodes=new Hashtable(); + + for(Iterator it_tasks=state.getTaskSymbolTable().getDescriptorsIterator();it_tasks.hasNext();){ + TaskDescriptor td=(TaskDescriptor)it_tasks.next(); + TaskNode tn=new TaskNode(td.getSymbol()); + alltasknodes.put(tn,tn); + } + TaskNode tn_runtime=new TaskNode("Runtime"); + alltasknodes.put(tn_runtime,tn_runtime); + + int ColorID=0; + for(Iterator classit=state.getClassSymbolTable().getDescriptorsIterator();classit.hasNext()&&ColorID<10;) { + ClassDescriptor cd=(ClassDescriptor) classit.next(); + Set fsnodes; + + if (cd.hasFlags()&&((fsnodes=taskanalysis.getFlagStates(cd))!=null)){ + System.out.println(cd.getSymbol()); + for(Iterator it=fsnodes.iterator();it.hasNext();) { + FlagState fs=(FlagState)it.next(); + Iterator it_inedges=fs.inedges(); + TaskNode tn,sn; + + + if (fs.isSourceNode()){ + if(fs.edges().hasNext()){ + Vector allocatingtasks=fs.getAllocatingTasks(); + for(Iterator it_at=allocatingtasks.iterator();it_at.hasNext();){ + tn=new TaskNode(((TaskDescriptor)it_at.next()).getSymbol()); + addEdges(fs,tn,alltasknodes,ColorID); + } + } + } + + while(it_inedges.hasNext()){ + FEdge inedge=(FEdge)it_inedges.next(); + tn=new TaskNode(inedge.getLabel()); + if(fs.edges().hasNext()){ + addEdges(fs,tn,alltasknodes,ColorID); + } + } + } + ColorID++; + } + + } + } + + public Set getAllTaskNodes(){ + return alltasknodes.keySet(); + } + + + + + + + + /* private void mergeAllNodes(){ Hashtable alltasks=new Hashtable(); for(Iterator classit=state.getClassSymbolTable().getDescriptorsIterator();classit.hasNext();) { @@ -111,9 +177,9 @@ public class TaskGraph { */ - private void addEdges(FlagState fs, TaskNode tn){ + private void addEdges(FlagState fs, TaskNode tn,Hashtable tasknodes){ - Hashtable tasknodes=(Hashtable)cdtonodes.get(fs.getClassDescriptor()); + // 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()); @@ -121,10 +187,24 @@ public class TaskGraph { TEdge newedge=new TEdge(target); if (! tn.edgeExists(newedge)) - tn.addEdge(new TEdge(target)); + tn.addEdge(newedge); } } + private void addEdges(FlagState fs, TaskNode tn,Hashtable tasknodes,int ColorID){ + + 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); + newedge.setDotNodeParameters("style=bold, color = "+colors[ColorID]); + if (! tn.edgeExists(newedge)) + tn.addEdge(newedge); + } + + } } diff --git a/Robust/src/Interface/WebInterface.java b/Robust/src/Interface/WebInterface.java index b55415e8..9b4d49c2 100644 --- a/Robust/src/Interface/WebInterface.java +++ b/Robust/src/Interface/WebInterface.java @@ -25,30 +25,37 @@ public class WebInterface { taskgraphmap=new Hashtable(); taskmap = new Hashtable(); sourcenodemap=new Hashtable(); + for(Iterator it_tasks=state.getTaskSymbolTable().getDescriptorsIterator();it_tasks.hasNext();){ TaskDescriptor td=(TaskDescriptor)it_tasks.next(); taskmap.put("/"+td.getSymbol()+".html",td); } + for(Iterator it_classes=state.getClassSymbolTable().getDescriptorsIterator();it_classes.hasNext();) { ClassDescriptor cd=(ClassDescriptor) it_classes.next(); - Vector rootnodes=taskanalysis.getRootNodes(cd); - if(rootnodes!=null) - for(Iterator it_rootnodes=rootnodes.iterator();it_rootnodes.hasNext();){ - FlagState root=(FlagState)it_rootnodes.next(); - Vector cd_nodeid=new Vector(); //Vector is designed to contain only 2 elements: ClassDescriptor,Node label + if(cd.hasFlags()){ + Vector rootnodes=taskanalysis.getRootNodes(cd); + + if(rootnodes!=null) + for(Iterator it_rootnodes=rootnodes.iterator();it_rootnodes.hasNext();){ + FlagState root=(FlagState)it_rootnodes.next(); + Vector cd_nodeid=new Vector(); //Vector is designed to contain only 2 elements: ClassDescriptor,Node label // Both the values are required to correctly resolve the rootnode. // Should think of a better way to do this, instead of using a vector(maybe a class) - cd_nodeid.addElement(cd); //adding the ClassDescriptor - cd_nodeid.addElement(root.getLabel()); //adding the Node label - sourcenodemap.put("/"+cd.getSymbol()+"_"+root.getLabel()+".html",cd_nodeid); - } - } + cd_nodeid.addElement(cd); //adding the ClassDescriptor + cd_nodeid.addElement(root.getLabel()); //adding the Node label + sourcenodemap.put("/"+cd.getSymbol()+"_"+root.getLabel()+".html",cd_nodeid); + } + } } + } public boolean specialRequest(String filename) { System.out.println(filename); if (filename.equals("/index.html")) return true; + if (filename.equals("/UnifiedTaskGraph.html")) + return true; if (flagstatemap.containsKey(filename)) return true; if (taskgraphmap.containsKey(filename)) @@ -63,6 +70,8 @@ public class WebInterface { public String handleresponse(String filename, OutputStream out, HTTPResponse resp) { if (filename.equals("/index.html")) return indexpage(out, resp); + if (filename.equals("/UnifiedTaskGraph.html")) + return unifiedTaskGraph(out,resp); if (flagstatemap.containsKey(filename)) return flagstate((ClassDescriptor) flagstatemap.get(filename), out, resp); if (taskgraphmap.containsKey(filename)) @@ -212,8 +221,40 @@ public class WebInterface { taskgraphmap.put("/"+cd.getSymbol()+"-t.html", cd); } } + pw.println("

Program flow"); pw.flush(); return null; } + + private String unifiedTaskGraph(OutputStream out, HTTPResponse resp){ + Set objects=taskgraph.getAllTaskNodes(); + File file=new File("UnifiedTaskGraph.dot"); + /*File mapfile; + String str; + Vector namers=new Vector(); + namers.add(new Namer()); + namers.add(new TaskNodeNamer()); +*/ + try { + //Generate jpg + Runtime r=Runtime.getRuntime(); + FileOutputStream dotstream=new FileOutputStream(file,false); + FlagState.DOTVisitor.visit(dotstream, objects); + dotstream.close(); + Process p=r.exec("dot -Tjpg -oUnifiedTaskGraph.jpg UnifiedTaskGraph.dot"); + p.waitFor(); + p=r.exec("dot -Tps UnifiedTaskGraph.dot -oUnifiedTaskGraph.ps"); + + p.waitFor(); + + PrintWriter pw=new PrintWriter(out); + pw.println("ps
"); + // pw.println(""); + pw.println(""); + + pw.flush(); + } catch (Exception e) {e.printStackTrace();System.exit(-1);} + return null; + } } diff --git a/Robust/src/Util/Edge.java b/Robust/src/Util/Edge.java index 20e93d9b..1f35e8aa 100644 --- a/Robust/src/Util/Edge.java +++ b/Robust/src/Util/Edge.java @@ -32,7 +32,7 @@ public class Edge { throw new NullPointerException(); } if (param.length() > 0) { - dotnodeparams = "," + param; + dotnodeparams = param; } else { dotnodeparams = new String(); } -- 2.34.1