X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=Robust%2Fsrc%2FAnalysis%2FTaskStateAnalysis%2FTaskAnalysis.java;h=bba02a6edb955f4bcfa990bb7ff06f95ed6e9105;hb=4cb63e913202459da4fe9d01feb7c02f1b98dd6f;hp=6da94379bc60418b66f4dbb1f5f18611a13fb679;hpb=2353220dc04368be57a09229fc002f8e7d34f6d3;p=IRC.git diff --git a/Robust/src/Analysis/TaskStateAnalysis/TaskAnalysis.java b/Robust/src/Analysis/TaskStateAnalysis/TaskAnalysis.java index 6da94379..bba02a6e 100644 --- a/Robust/src/Analysis/TaskStateAnalysis/TaskAnalysis.java +++ b/Robust/src/Analysis/TaskStateAnalysis/TaskAnalysis.java @@ -15,6 +15,7 @@ public class TaskAnalysis { Queue toprocess; TagAnalysis taganalysis; Hashtable cdtorootnodes; + Hashtable tdToFEdges; TypeUtil typeutil; @@ -24,25 +25,25 @@ public class TaskAnalysis { * @param state a flattened State object * @see State */ - public TaskAnalysis(State state, TagAnalysis taganalysis) - { + public TaskAnalysis(State state, TagAnalysis taganalysis) { this.state=state; this.typeutil=new TypeUtil(state); this.taganalysis=taganalysis; - } - /** Builds a table of flags for each class in the Bristlecone program. - * It creates two hashtables: one which holds the ClassDescriptors and arrays of - * FlagDescriptors as key-value pairs; the other holds the ClassDescriptor and the - * number of external flags for that specific class. + /** Builds a table of flags for each class in the Bristlecone + * program. It creates two hashtables: one which holds the + * ClassDescriptors and arrays of * FlagDescriptors as key-value + * pairs; the other holds the ClassDescriptor and the * number of + * external flags for that specific class. */ private void getFlagsfromClasses() { flags=new Hashtable(); extern_flags = new Hashtable(); - /** Iterate through the classes used in the program to build the table of flags + /** Iterate through the classes used in the program to build + * the table of flags */ for(Iterator it_classes=state.getClassSymbolTable().getDescriptorsIterator();it_classes.hasNext();) { @@ -53,19 +54,15 @@ public class TaskAnalysis { /* Adding the flags of the super class */ - if (cd.getSuper()!=null) { - ClassDescriptor superdesc=cd.getSuperDesc(); - - for(Iterator it_cflags=superdesc.getFlags();it_cflags.hasNext();) { + ClassDescriptor tmp=cd; + while(tmp!=null) { + for(Iterator it_cflags=tmp.getFlags();it_cflags.hasNext();) { FlagDescriptor fd = (FlagDescriptor)it_cflags.next(); vFlags.add(fd); } + tmp=tmp.getSuperDesc(); } - for(Iterator it_cflags=cd.getFlags();it_cflags.hasNext();) { - FlagDescriptor fd = (FlagDescriptor)it_cflags.next(); - vFlags.add(fd); - } if (vFlags.size()!=0) { flag=new FlagDescriptor[vFlags.size()]; @@ -86,14 +83,14 @@ public class TaskAnalysis { } } } - /** Method which starts up the analysis - * + /** Method which starts up the analysis */ public void taskAnalysis() throws java.io.IOException { flagstates=new Hashtable(); Hashtable sourcenodes; cdtorootnodes=new Hashtable(); + tdToFEdges=new Hashtable(); getFlagsfromClasses(); @@ -124,15 +121,14 @@ public class TaskAnalysis { sourcenodes.put(fsstartup,fsstartup); toprocess.add(fsstartup); - /** Looping through the flagstates in the toprocess queue to perform the state analysis */ + /** Looping through the flagstates in the toprocess queue to + * perform the state analysis */ while (!toprocess.isEmpty()) { FlagState trigger=toprocess.poll(); createPossibleRuntimeStates(trigger); analyseTasks(trigger); } - - /** Creating DOT files */ Enumeration e=flagstates.keys(); @@ -159,23 +155,31 @@ private void analyseTasks(FlagState fs) { TaskDescriptor td = (TaskDescriptor)it_tasks.next(); String taskname=td.getSymbol(); - /** counter to keep track of the number of parameters (of the task being analyzed) that - * are satisfied by the flagstate. + if(!tdToFEdges.containsKey(td)) { + tdToFEdges.put(td, new Vector()); + } + + /** counter to keep track of the number of parameters (of the + * task being analyzed) that are satisfied by the flagstate. */ int trigger_ctr=0; TempDescriptor temp=null; FlatMethod fm = state.getMethodFlat(td); - + int parameterindex=0; + for(int i=0; i < td.numParameters(); i++) { FlagExpressionNode fen=td.getFlag(td.getParameter(i)); TagExpressionList tel=td.getTag(td.getParameter(i)); - /** Checking to see if the parameter is of the same type/class as the - * flagstate's and also if the flagstate fs triggers the given task*/ + /** Checking to see if the parameter is of the same + * type/class as the flagstate's and also if the + * flagstate fs triggers the given task*/ + if (typeutil.isSuperorType(td.getParamType(i).getClassDesc(),cd) && isTaskTrigger_flag(fen,fs) && isTaskTrigger_tag(tel,fs)) { temp=fm.getParameter(i); + parameterindex=i; trigger_ctr++; } } @@ -184,19 +188,25 @@ private void analyseTasks(FlagState fs) { continue; if (trigger_ctr>1) - throw new Error("Illegal Operation: A single flagstate cannot satisfy more than one parameter of a task."); + System.out.println("Illegal Operation: A single flagstate cannot satisfy more than one parameter of a task:"+fs + " in "+td); 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); + System.out.println("SOURCE:"+fsnew); if (! ((Hashtable)flagstates.get(fsnew.getClassDescriptor())).containsKey(fsnew)) { ((Hashtable)flagstates.get(fsnew.getClassDescriptor())).put(fsnew, fsnew); toprocess.add(fsnew); + } else { + fsnew=((Hashtable)flagstates.get(fsnew.getClassDescriptor())).get(fsnew); + } + fsnew.setAsSourceNode(); + fsnew.addAllocatingTask(td); + + if(!((Vector)cdtorootnodes.get(fsnew.getClassDescriptor())).contains(fsnew)) { + ((Vector)cdtorootnodes.get(fsnew.getClassDescriptor())).add(fsnew); } } @@ -211,7 +221,8 @@ private void analyseTasks(FlagState fs) { if (fn1.kind()==FKind.FlatReturnNode) { /* Self edge */ - FEdge newedge=new FEdge(fs, taskname); + FEdge newedge=new FEdge(fs, taskname, td, parameterindex); + ((Vector)tdToFEdges.get(td)).add(newedge); fs.addEdge(newedge); continue; } else if (fn1.kind()==FKind.FlatFlagActionNode) { @@ -222,6 +233,11 @@ private void analyseTasks(FlagState fs) { } else if (ffan.getTaskType() == FlatFlagActionNode.TASKEXIT) { Vector fsv_taskexit=evalTaskExitNode(ffan,cd,fs,temp); + Vector initFStates = ffan.getInitFStates(temp.getType().getClassDesc()); + if(!initFStates.contains(fs)) { + initFStates.addElement(fs); + } + Vector targetFStates = ffan.getTargetFStates(fs); for(Enumeration en=fsv_taskexit.elements();en.hasMoreElements();){ FlagState fs_taskexit=(FlagState)en.nextElement(); if (!sourcenodes.containsKey(fs_taskexit)) { @@ -229,8 +245,13 @@ private void analyseTasks(FlagState fs) { } //seen this node already fs_taskexit=canonicalizeFlagState(sourcenodes,fs_taskexit); - FEdge newedge=new FEdge(fs_taskexit,taskname); + FEdge newedge=new FEdge(fs_taskexit,taskname, td, parameterindex); + ((Vector)tdToFEdges.get(td)).add(newedge); fs.addEdge(newedge); + + if(!targetFStates.contains(fs_taskexit)) { + targetFStates.addElement(fs_taskexit); + } } continue; } @@ -259,7 +280,7 @@ private void analyseTasks(FlagState fs) { */ -private boolean isTaskTrigger_flag(FlagExpressionNode fen,FlagState fs) { +public static boolean isTaskTrigger_flag(FlagExpressionNode fen,FlagState fs) { if (fen==null) return true; else if (fen instanceof FlagNode) @@ -293,14 +314,6 @@ private boolean isTaskTrigger_tag(TagExpressionList tel, FlagState fs){ return true; } -/*private int tagTypeCount(TagExpressionList tel, String tagtype){ - int ctr=0; - for(int i=0;i evalTaskExitNode(FlatFlagActionNode ffan,ClassDescriptor cd,FlagState fs, TempDescriptor temp){ FlagState fstemp=fs; @@ -371,60 +384,61 @@ private boolean isTaskTrigger_tag(TagExpressionList tel, FlagState fs){ 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); + FileOutputStream dotstream=new FileOutputStream(dotfile_flagstates,false); FlagState.DOTVisitor.visit(dotstream,((Hashtable)flagstates.get(cd)).values()); } /** Returns the flag states for the class descriptor. */ - public Set getFlagStates(ClassDescriptor cd) { + public Set getFlagStates(ClassDescriptor cd) { if (flagstates.containsKey(cd)) - return ((Hashtable)flagstates.get(cd)).keySet(); + return ((Hashtable)flagstates.get(cd)).keySet(); else - return null; + return new HashSet(); } private void createPossibleRuntimeStates(FlagState fs) { - ClassDescriptor cd = fs.getClassDescriptor(); - Hashtable sourcenodes=(Hashtable)flagstates.get(cd); - FlagDescriptor[] fd=(FlagDescriptor[])flags.get(cd); - int externs=((Integer)extern_flags.get(cd)).intValue(); - - if(externs==0) - return; - - int noOfIterations=(1< sourcenodes=(Hashtable)flagstates.get(cd); + FlagDescriptor[] fd=(FlagDescriptor[])flags.get(cd); + int externs=((Integer)extern_flags.get(cd)).intValue(); - FlagState fstemp=fs; + if(externs==0) + return; + + int noOfIterations=(1<