changes to handle fixed point analysis properly + bug fix.
[IRC.git] / Robust / src / Analysis / Scheduling / ClassNode.java
1 package Analysis.Scheduling;
2
3 import Analysis.TaskStateAnalysis.*;
4 import IR.*;
5 import java.util.*;
6
7 import Util.GraphNode;
8
9 /** This class holds a flag diagram for one class.
10  */
11 public class ClassNode extends GraphNode implements Cloneable {
12
13   private int uid;
14   private int cid;
15   private static int nodeID=0;
16   private static int colorID = 1;
17   private static Hashtable<ClassDescriptor, Integer> cd2cid = 
18       new Hashtable<ClassDescriptor, Integer>(); 
19
20   private final ClassDescriptor cd;
21   private ScheduleNode sn;
22   private Vector<FlagState> flagStates;
23   private boolean sorted = false;
24   private boolean clone = false;
25
26   private long transTime;
27
28   /** Class constructor
29    *    @param cd ClassDescriptor
30    *  @param fStates
31    */
32   public ClassNode(ClassDescriptor cd, 
33                    Vector<FlagState> fStates) {
34     this.cd=cd;
35     this.flagStates = fStates;
36     this.sn = null;
37     this.uid=ClassNode.nodeID++;
38     // TODO: potential bug here
39     // DO NOT consider splitting a class node here.
40     // need to fix: 1. when a class node is splitted, the pieces should have 
41     //                 different cid
42     //              2. when two pieces merged, it should have right cid as have
43     //                 never been splitted
44     //              3. NOTE: a piece could be splitted further
45     if(this.cd2cid.containsKey(cd)) {
46         this.cid = this.cd2cid.get(cd);
47     } else {
48         this.cid = ClassNode.colorID++;
49         this.cd2cid.put(this.cd, this.cid);
50     }
51     this.transTime = 0;
52   }
53
54   public long getTransTime() {
55     return this.transTime;
56   }
57
58   public void setTransTime(long transTime) {
59     this.transTime = transTime;
60   }
61
62   public int getuid() {
63     return uid;
64   }
65
66   public int getCid() {
67       return cid;
68   }
69
70   public ScheduleNode getScheduleNode() {
71     return this.sn;
72   }
73
74   public void setScheduleNode(ScheduleNode sn) {
75     this.sn = sn;
76   }
77
78   public boolean isSorted() {
79     return sorted;
80   }
81
82   public void setSorted(boolean sorted) {
83     this.sorted = sorted;
84   }
85
86   public Vector<FlagState> getFlagStates() {
87     return flagStates;
88   }
89
90   public boolean isclone() {
91     return clone;
92   }
93
94   public String toString() {
95     return cd.toString()+getTextLabel();
96   }
97
98   /** @return Iterator over the flags in the flagstate.
99    */
100
101   public Iterator getFlags() {
102     return flagStates.iterator();
103   }
104
105   public int numFlags() {
106     return flagStates.size();
107   }
108
109   /** Accessor method
110    *  @return returns the classdescriptor of the flagstate.
111    */
112
113   public ClassDescriptor getClassDescriptor() {
114     return cd;
115   }
116
117   /** Tests for equality of two flagstate objects.
118    */
119
120   public boolean equals(Object o) {
121     if (o instanceof ClassNode) {
122       ClassNode fs=(ClassNode)o;
123       if ((fs.getClassDescriptor()!= cd) ||
124           (fs.getuid()!= uid) ||
125           (fs.getCid()!= cid) ||
126           (fs.isSorted() != sorted) ||
127           (fs.clone != this.clone) ||
128           (fs.transTime != this.transTime)) {
129         return false;
130       }
131       return (fs.getFlagStates().equals(flagStates));
132     }
133     return false;
134   }
135
136   public int hashCode() {
137     return cd.hashCode()^uid^cid^Boolean.toString(sorted).hashCode()^
138            Boolean.toString(clone).hashCode()^(int)transTime^flagStates.hashCode();
139   }
140
141   public String getLabel() {
142     return "N_"+uid;
143   }
144
145   public String getClusterLabel() {
146     return "cluster_"+uid;
147   }
148
149   public String getTextLabel() {
150     String label=null;
151     label = "Class " + this.cd.getSymbol();
152
153     if (label==null)
154       return " ";
155     return label;
156   }
157
158   public Object clone() {
159     ClassNode o = null;
160     try {
161       o = (ClassNode) super.clone();
162     } catch(CloneNotSupportedException e) {
163       e.printStackTrace();
164     }
165     o.uid = ClassNode.nodeID++;
166     o.cid = this.cid;
167     o.clone = true;
168     return o;
169   }
170
171   public void calExeTime() {
172     for(int i = 0; i <  this.flagStates.size(); i++) {
173       this.flagStates.elementAt(i).getExeTime();
174     }
175   }
176 }