X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=Robust%2Fsrc%2FAnalysis%2FTaskStateAnalysis%2FFlagState.java;h=58bd822f478f7c59049db61c18091f8baabe9d03;hb=cdcf09c40af1419fa42932aae249cb79b69b5daf;hp=06e4fdf54ff64c491fcb42fee36ffdd90341f973;hpb=9ba661cac6f52c0af850e576fb67dabad3e91aeb;p=IRC.git diff --git a/Robust/src/Analysis/TaskStateAnalysis/FlagState.java b/Robust/src/Analysis/TaskStateAnalysis/FlagState.java deleted file mode 100644 index 06e4fdf5..00000000 --- a/Robust/src/Analysis/TaskStateAnalysis/FlagState.java +++ /dev/null @@ -1,388 +0,0 @@ -package Analysis.TaskStateAnalysis; - -import Analysis.TaskStateAnalysis.*; -import IR.*; -import IR.Tree.*; -import IR.Flat.*; -import java.util.*; -import java.io.*; -import Util.GraphNode; - -/** This class is used to hold the flag states that a class in the Bristlecone - * program can exist in, during runtime. - */ -public class FlagState extends GraphNode implements Cloneable { - public static final int ONETAG=1; - public static final int NOTAGS=0; - public static final int MULTITAGS=-1; - - private int uid; - private static int nodeid=0; - - private final HashSet flagstate; - private final ClassDescriptor cd; - private final Hashtable tags; - private boolean issourcenode; - private Vector tasks; - public static final int KLIMIT=2; - - // jzhou - private int executeTime; - private int invokeNum; - - /** Class constructor - * Creates a new flagstate with all flags set to false. - * @param cd ClassDescriptor - */ - public FlagState(ClassDescriptor cd) { - this.flagstate=new HashSet(); - this.cd=cd; - this.tags=new Hashtable(); - this.uid=FlagState.nodeid++; - this.issourcenode=false; - this.executeTime = -1; - this.invokeNum = 0; - } - - /** Class constructor - * Creates a new flagstate with flags set according to the HashSet. - * If the flag exists in the hashset, it's set to true else set to false. - * @param cd ClassDescriptor - * @param flagstate a HashSet containing FlagDescriptors - */ - private FlagState(HashSet flagstate, ClassDescriptor cd,Hashtable tags) { - this.flagstate=flagstate; - this.cd=cd; - this.tags=tags; - this.uid=FlagState.nodeid++; - this.issourcenode=false; - this.executeTime = -1; - this.invokeNum = 0; - } - - public int getuid() { - return uid; - } - - /** Accessor method - * @param fd FlagDescriptor - * @return true if the flagstate contains fd else false. - */ - 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(){ - if(!issourcenode){ - issourcenode=true; - this.tasks=new Vector(); - } - } - - public void addAllocatingTask(TaskDescriptor task){ - tasks.add(task); - } - - public Vector getAllocatingTasks(){ - return tasks; - } - - - public String toString() { - return cd.toString()+getTextLabel(); - } - - /** @return Iterator over the flags in the flagstate. - */ - - public Iterator getFlags() { - return flagstate.iterator(); - } - - public int numFlags(){ - return flagstate.size(); - } - - public FlagState[] setTag(TagDescriptor tag, boolean set){ - HashSet newset1=(HashSet)flagstate.clone(); - Hashtable newtags1=(Hashtable)tags.clone(); - - if (set) { - int count=0; - if (tags.containsKey(tag)) - count=tags.get(tag).intValue(); - if (count newtags1=(Hashtable)tags.clone(); - - if (tags.containsKey(tag)){ - //Code could try to remove flag that doesn't exist - - switch (tags.get(tag).intValue()){ - case ONETAG: - newtags1.put(tag,new Integer(MULTITAGS)); - return new FlagState[] {this, new FlagState(newset1, cd, newtags1)}; - case MULTITAGS: - return new FlagState[] {this}; - default: - throw new Error(); - } - } else { - newtags1.put(tag,new Integer(ONETAG)); - return new FlagState[] {new FlagState(newset1,cd,newtags1)}; - } - } - - public int getTagCount(TagDescriptor tag) { - if (tags.containsKey(tag)) - return tags.get(tag).intValue(); - else return 0; - } - - public int getTagCount(String tagtype){ - return getTagCount(new TagDescriptor(tagtype)); - } - - public FlagState[] clearTag(TagDescriptor tag){ - if (tags.containsKey(tag)){ - switch(tags.get(tag).intValue()){ - case ONETAG: - HashSet newset=(HashSet)flagstate.clone(); - Hashtable newtags=(Hashtable)tags.clone(); - newtags.remove(tag); - return new FlagState[]{new FlagState(newset,cd,newtags)}; - - case MULTITAGS: - //two possibilities - count remains 2 or becomes 1 - //2 case - HashSet newset1=(HashSet)flagstate.clone(); - Hashtable newtags1=(Hashtable)tags.clone(); - - //1 case - HashSet newset2=(HashSet)flagstate.clone(); - Hashtable newtags2=(Hashtable)tags.clone(); - newtags1.put(tag,new Integer(ONETAG)); - return new FlagState[] {new FlagState(newset1, cd, newtags2), - new FlagState(newset2, cd, newtags2)}; - default: - throw new Error(); - } - } else { - throw new Error("Invalid Operation: Can not clear a tag that doesn't exist."); - } - } - - /** Creates a string description of the flagstate - * e.g. a flagstate with five flags could look like 01001 - * @param flags an array of flagdescriptors. - * @return string representation of the flagstate. - */ - public String toString(FlagDescriptor[] flags) - { - StringBuffer sb = new StringBuffer(flagstate.size()); - for(int i=0;i < flags.length; i++) - { - if (get(flags[i])) - sb.append(1); - else - sb.append(0); - } - - return new String(sb); - } - - /** Accessor method - * @return returns the classdescriptor of the flagstate. - */ - - public ClassDescriptor getClassDescriptor(){ - return cd; - } - - /** Sets the status of a specific flag in a flagstate after cloning it. - * @param fd FlagDescriptor of the flag whose status is being set. - * @param status boolean value - * @return the new flagstate with fd set to status. - */ - - public FlagState setFlag(FlagDescriptor fd, boolean status) { - HashSet newset=(HashSet) flagstate.clone(); - Hashtable newtags=(Hashtable)tags.clone(); - if (status) - newset.add(fd); - else if (newset.contains(fd)){ - newset.remove(fd); - } - - return new FlagState(newset, cd, newtags); - } - - /** Tests for equality of two flagstate objects. - */ - - public boolean equals(Object o) { - if (o instanceof FlagState) { - FlagState fs=(FlagState)o; - if (fs.cd!=cd) - return false; - return (fs.flagstate.equals(flagstate) & fs.tags.equals(tags)); - } - return false; - } - - public int hashCode() { - return cd.hashCode()^flagstate.hashCode()^tags.hashCode(); - } - - public String getLabel() { - return "N"+uid; - } - - public String getTextLabel() { - String label=null; - for(Iterator it=getFlags();it.hasNext();) { - FlagDescriptor fd=(FlagDescriptor) it.next(); - if (label==null) - label=fd.toString(); - else - label+=", "+fd.toString(); - } - for (Enumeration en_tags=getTags();en_tags.hasMoreElements();){ - TagDescriptor td=(TagDescriptor)en_tags.nextElement(); - switch (tags.get(td).intValue()){ - case ONETAG: - if (label==null) - label=td.toString()+"(1)"; - else - label+=", "+td.toString()+"(1)"; - break; - case MULTITAGS: - if (label==null) - label=td.toString()+"(n)"; - else - label+=", "+td.toString()+"(n)"; - break; - default: - break; - } - } - if (label==null) - return " "; - return label; - } - - public Enumeration getTags(){ - return tags.keys(); - } - - public int getExeTime() { - try { - if(this.executeTime == -1) { - calExeTime(); - } - } catch (Exception e) { - e.printStackTrace(); - System.exit(0); - } - return this.executeTime; - } - - public void setExeTime(int exeTime) { - this.executeTime = exeTime; - } - - public void calExeTime() throws Exception { - Iterator it = this.edges(); - if(it.hasNext()) { - FEdge fe = (FEdge)it.next(); - if(fe.getExeTime() == -1) { - throw new Exception("Error: Uninitiate FEdge!"); - } - this.executeTime = fe.getExeTime() + ((FlagState)fe.getTarget()).getExeTime(); - } else { - this.executeTime = 0; - } - while(it.hasNext()) { - FEdge fe = (FEdge)it.next(); - int temp = fe.getExeTime() + ((FlagState)fe.getTarget()).getExeTime(); - if(temp < this.executeTime) { - this.executeTime = temp; - } - } - } - - public Object clone() { - FlagState o = null; - try { - o = (FlagState)super.clone(); - } catch(CloneNotSupportedException e){ - e.printStackTrace(); - } - o.uid = FlagState.nodeid++; - o.edges = new Vector(); - for(int i = 0; i < this.edges.size(); i++) { - o.edges.addElement(this.edges.elementAt(i)); - } - o.inedges = new Vector(); - for(int i = 0; i < this.inedges.size(); i++) { - o.inedges.addElement(this.inedges.elementAt(i)); - } - return o; - } - - public void init4Simulate() { - this.invokeNum = 0; - } - - public FEdge process(TaskDescriptor td) { - FEdge next = null; - this.invokeNum++; - // refresh all the expInvokeNum of each edge - for(int i = 0; i < this.edges.size(); i++) { - next = (FEdge)this.edges.elementAt(i); - next.setExpInvokeNum((int)Math.round(this.invokeNum * (next.getProbability() / 100))); - } - - // find the one with the biggest gap between its actual invoke time and the expected invoke time - // and associated with task td - int index = 0; - int gap = 0; - for(int i = 0; i < this.edges.size(); i++) { - int temp = ((FEdge)this.edges.elementAt(index)).getInvokeNumGap(); - if((temp > gap) && (next.getTask().equals(td))){ - index = i; - gap = temp; - } - } - next = (FEdge)this.edges.elementAt(index); - next.process(); - - return next; - } -}