X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=Robust%2Fsrc%2FAnalysis%2FTaskStateAnalysis%2FTaskAnalysis.java;h=c5b626a943b54fb6fba5f91b1167de91791cc920;hb=e657f2b3171b3fa1c6af965d71b9cf32066e407a;hp=42c07e570765ee0ac43f9577c3b1adf7b5b67e3e;hpb=07f496261153888cc9f80492c03131f10d3168a2;p=IRC.git diff --git a/Robust/src/Analysis/TaskStateAnalysis/TaskAnalysis.java b/Robust/src/Analysis/TaskStateAnalysis/TaskAnalysis.java index 42c07e57..c5b626a9 100644 --- a/Robust/src/Analysis/TaskStateAnalysis/TaskAnalysis.java +++ b/Robust/src/Analysis/TaskStateAnalysis/TaskAnalysis.java @@ -14,6 +14,7 @@ public class TaskAnalysis { Hashtable extern_flags; Queue toprocess; TagAnalysis taganalysis; + Hashtable cdtorootnodes; TypeUtil typeutil; @@ -28,6 +29,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. @@ -45,7 +47,6 @@ public class TaskAnalysis { for(Iterator it_classes=state.getClassSymbolTable().getDescriptorsIterator();it_classes.hasNext();) { ClassDescriptor cd = (ClassDescriptor)it_classes.next(); - System.out.println(cd.getSymbol()); Vector vFlags=new Vector(); FlagDescriptor flag[]; int ctr=0; @@ -57,7 +58,6 @@ public class TaskAnalysis { for(Iterator it_cflags=superdesc.getFlags();it_cflags.hasNext();) { FlagDescriptor fd = (FlagDescriptor)it_cflags.next(); - System.out.println(fd.toString()); vFlags.add(fd); } } @@ -93,7 +93,7 @@ public class TaskAnalysis { public void taskAnalysis() throws java.io.IOException { flagstates=new Hashtable(); Hashtable sourcenodes; - + cdtorootnodes=new Hashtable(); getFlagsfromClasses(); @@ -104,26 +104,23 @@ public class TaskAnalysis { ClassDescriptor cd=(ClassDescriptor)it_classes.next(); externs=((Integer)extern_flags.get(cd)).intValue(); FlagDescriptor[] fd=(FlagDescriptor[])flags.get(cd); - - //Debug block - System.out.println("Inside taskAnalysis;\n Class:"+ cd.getSymbol()); - System.out.println("No of externs " + externs); - System.out.println("No of flags: "+fd.length); - //Debug block - flagstates.put(cd,new Hashtable()); + cdtorootnodes.put(cd,new Vector()); } ClassDescriptor startupobject=typeutil.getClass(TypeUtil.StartupClass); sourcenodes=(Hashtable)flagstates.get(startupobject); - FlagState fsstartup=new FlagState(startupobject); + + FlagDescriptor[] fd=(FlagDescriptor[])flags.get(startupobject); fsstartup=fsstartup.setFlag(fd[0],true); - + fsstartup.setAsSourceNode(); + ((Vector)cdtorootnodes.get(startupobject)).add(fsstartup); + sourcenodes.put(fsstartup,fsstartup); toprocess.add(fsstartup); @@ -139,9 +136,7 @@ public class TaskAnalysis { Enumeration e=flagstates.keys(); while (e.hasMoreElements()) { - System.out.println("creating dot file"); ClassDescriptor cdtemp=(ClassDescriptor)e.nextElement(); - System.out.println((cdtemp.getSymbol())); createDOTfile(cdtemp); } } @@ -162,12 +157,6 @@ private void analyseTasks(FlagState fs) { TaskDescriptor td = (TaskDescriptor)it_tasks.next(); String taskname=td.getSymbol(); - //**Debug***/ - System.out.println(); - System.out.println(cd.getSymbol()+" : "+fs.getTextLabel()); - System.out.println("Task: "+taskname); - //*********** - /** counter to keep track of the number of parameters (of the task being analyzed) that * are satisfied by the flagstate. */ @@ -196,50 +185,60 @@ private void analyseTasks(FlagState fs) { throw new Error("Illegal Operation: A single flagstate cannot satisfy more than one parameter of a task."); - //** debug - System.out.println("Task:" + taskname +" is triggered"); - - Set newstates=taganalysis.getFlagStates(td); for(Iterator fsit=newstates.iterator();fsit.hasNext();) { FlagState fsnew=(FlagState) fsit.next(); + fsnew.setAsSourceNode(); + fsnew.addAllocatingTask(td); + ((Vector)cdtorootnodes.get(fsnew.getClassDescriptor())).add(fsnew); + if (! ((Hashtable)flagstates.get(fsnew.getClassDescriptor())).containsKey(fsnew)) { ((Hashtable)flagstates.get(fsnew.getClassDescriptor())).put(fsnew, fsnew); toprocess.add(fsnew); } } + Stack nodestack=new Stack(); + HashSet discovered=new HashSet(); + nodestack.push(fm); + discovered.add(fm); //Iterating through the nodes - Set nodeset=fm.getNodeSet(); - for(Iterator nodeit=nodeset.iterator();nodeit.hasNext();) { - FlatNode fn1 = (FlatNode) nodeit.next(); + while(!nodestack.isEmpty()) { + FlatNode fn1 = (FlatNode) nodestack.pop(); - if (fn1.kind()==FKind.FlatFlagActionNode) { + if (fn1.kind()==FKind.FlatReturnNode) { + /* Self edge */ + FEdge newedge=new FEdge(fs, taskname); + fs.addEdge(newedge); + continue; + } else if (fn1.kind()==FKind.FlatFlagActionNode) { FlatFlagActionNode ffan=(FlatFlagActionNode)fn1; if (ffan.getTaskType() == FlatFlagActionNode.PRE) { if (ffan.getTempFlagPairs().hasNext()||ffan.getTempTagPairs().hasNext()) throw new Error("PRE FlagActions not supported"); } else if (ffan.getTaskType() == FlatFlagActionNode.TASKEXIT) { - //*** - System.out.println("TASKEXIT"); - //*** - Vector fsv_taskexit=evalTaskExitNode(ffan,cd,fs,temp); - for(Enumeration en=fsv_taskexit.elements();en.hasMoreElements();){ FlagState fs_taskexit=(FlagState)en.nextElement(); if (!sourcenodes.containsKey(fs_taskexit)) { toprocess.add(fs_taskexit); - } //seen this node already fs_taskexit=canonicalizeFlagState(sourcenodes,fs_taskexit); FEdge newedge=new FEdge(fs_taskexit,taskname); - //FEdge newedge=new FEdge(fs_taskexit,td); fs.addEdge(newedge); } + continue; + } + } + /* Queue other nodes past this one */ + for(int i=0;i evalTaskExitNode(FlatFlagActionNode ffan,ClassDescriptor cd,FlagState fs, TempDescriptor temp){ + FlagState fstemp=fs; + Vector processed=new Vector(); + + //Process the flag changes - else - break; - } - for(Iterator it_ttp=((FlatFlagActionNode)nn).getTempTagPairs();it_ttp.hasNext();) { - TempTagPair ttp=(TempTagPair)it_ttp.next(); - if (! (ttp.getTag()==null)){ - fstemp=fstemp.setTag(ttp.getTag()); + for(Iterator it_tfp=ffan.getTempFlagPairs();it_tfp.hasNext();) { + TempFlagPair tfp=(TempFlagPair)it_tfp.next(); + if (temp==tfp.getTemp()) + fstemp=fstemp.setFlag(tfp.getFlag(),ffan.getFlagChange(tfp)); } - else - break; - } - return fstemp; -} + //Process the tag changes + + processed.add(fstemp); - private Vector evalTaskExitNode(FlatNode nn,ClassDescriptor cd,FlagState fs, TempDescriptor temp){ - FlagState fstemp=fs; - //FlagState[] fstemparray=new FlagState[3]; - Vector inprocess=new Vector(); - Vector processed=new Vector(); - - for(Iterator it_tfp=((FlatFlagActionNode)nn).getTempFlagPairs();it_tfp.hasNext();) { - TempFlagPair tfp=(TempFlagPair)it_tfp.next(); - if (temp==tfp.getTemp()) - fstemp=fstemp.setFlag(tfp.getFlag(),((FlatFlagActionNode)nn).getFlagChange(tfp)); - } - - inprocess.add(fstemp); - processed.add(fstemp); - - for(Iterator it_ttp=((FlatFlagActionNode)nn).getTempTagPairs();it_ttp.hasNext();) { - TempTagPair ttp=(TempTagPair)it_ttp.next(); - - if (temp==ttp.getTemp()){ - processed=new Vector(); - for (Enumeration en=inprocess.elements();en.hasMoreElements();){ - FlagState fsworking=(FlagState)en.nextElement(); - if (((FlatFlagActionNode)nn).getTagChange(ttp)){ - fsworking=fsworking.setTag(ttp.getTag()); - processed.add(fsworking); - } - else - { - processed.addAll(Arrays.asList(fsworking.clearTag(ttp.getTag()))); - } - } - inprocess=processed; - } + //Process clears first + for(Iterator it_ttp=ffan.getTempTagPairs();it_ttp.hasNext();) { + TempTagPair ttp=(TempTagPair)it_ttp.next(); + + if (temp==ttp.getTemp()) { + Vector oldprocess=processed; + processed=new Vector(); + + for (Enumeration en=oldprocess.elements();en.hasMoreElements();){ + FlagState fsworking=(FlagState)en.nextElement(); + if (!ffan.getTagChange(ttp)){ + processed.addAll(Arrays.asList(fsworking.clearTag(ttp.getTag()))); + } else processed.add(fsworking); } - return processed; - -} + } + } + //Process sets next + for(Iterator it_ttp=ffan.getTempTagPairs();it_ttp.hasNext();) { + TempTagPair ttp=(TempTagPair)it_ttp.next(); + if (temp==ttp.getTemp()) { + Vector oldprocess=processed; + processed=new Vector(); + + for (Enumeration en=oldprocess.elements();en.hasMoreElements();){ + FlagState fsworking=(FlagState)en.nextElement(); + if (ffan.getTagChange(ttp)){ + processed.addAll(Arrays.asList(fsworking.setTag(ttp.getTag()))); + } else processed.add(fsworking); + } + } + } + return processed; + } + private FlagState canonicalizeFlagState(Hashtable sourcenodes, FlagState fs){ if (sourcenodes.containsKey(fs)) @@ -399,12 +368,11 @@ private FlagState evalNewObjNode(FlatNode nn){ */ public void createDOTfile(ClassDescriptor cd) throws java.io.IOException { - File dotfile_flagstates= new File("graph"+cd.getSymbol()+".dot"); - FileOutputStream dotstream=new FileOutputStream(dotfile_flagstates,true); - FlagState.DOTVisitor.visit(dotstream,((Hashtable)flagstates.get(cd)).values()); - + File dotfile_flagstates= new File("graph"+cd.getSymbol()+".dot"); + FileOutputStream dotstream=new FileOutputStream(dotfile_flagstates,true); + FlagState.DOTVisitor.visit(dotstream,((Hashtable)flagstates.get(cd)).values()); } - + /** Returns the flag states for the class descriptor. */ public Set getFlagStates(ClassDescriptor cd) { if (flagstates.containsKey(cd)) @@ -450,7 +418,11 @@ private FlagState evalNewObjNode(FlatNode nn){ } } + public Vector getRootNodes(ClassDescriptor cd){ + return (Vector)cdtorootnodes.get(cd); + } - + + }