changes to handle fixed point analysis properly + bug fix.
[IRC.git] / Robust / src / Analysis / Scheduling / ClassNode.java
index e93cfe40beefa58f06bbfa903f66022089973fb7..0662f19a49b2dbbf7ae7470e98dfda109aae9114 100644 (file)
@@ -11,7 +11,11 @@ import Util.GraphNode;
 public class ClassNode extends GraphNode implements Cloneable {
 
   private int uid;
+  private int cid;
   private static int nodeID=0;
+  private static int colorID = 1;
+  private static Hashtable<ClassDescriptor, Integer> cd2cid = 
+      new Hashtable<ClassDescriptor, Integer>(); 
 
   private final ClassDescriptor cd;
   private ScheduleNode sn;
@@ -19,25 +23,39 @@ public class ClassNode extends GraphNode implements Cloneable {
   private boolean sorted = false;
   private boolean clone = false;
 
-  private int transTime;
+  private long transTime;
 
   /** Class constructor
    *   @param cd ClassDescriptor
    *  @param fStates
    */
-  public ClassNode(ClassDescriptor cd, Vector<FlagState> fStates) {
+  public ClassNode(ClassDescriptor cd, 
+                  Vector<FlagState> fStates) {
     this.cd=cd;
     this.flagStates = fStates;
     this.sn = null;
     this.uid=ClassNode.nodeID++;
+    // TODO: potential bug here
+    // DO NOT consider splitting a class node here.
+    // need to fix: 1. when a class node is splitted, the pieces should have 
+    //                 different cid
+    //              2. when two pieces merged, it should have right cid as have
+    //                 never been splitted
+    //              3. NOTE: a piece could be splitted further
+    if(this.cd2cid.containsKey(cd)) {
+       this.cid = this.cd2cid.get(cd);
+    } else {
+       this.cid = ClassNode.colorID++;
+       this.cd2cid.put(this.cd, this.cid);
+    }
     this.transTime = 0;
   }
 
-  public int getTransTime() {
+  public long getTransTime() {
     return this.transTime;
   }
 
-  public void setTransTime(int transTime) {
+  public void setTransTime(long transTime) {
     this.transTime = transTime;
   }
 
@@ -45,6 +63,10 @@ public class ClassNode extends GraphNode implements Cloneable {
     return uid;
   }
 
+  public int getCid() {
+      return cid;
+  }
+
   public ScheduleNode getScheduleNode() {
     return this.sn;
   }
@@ -99,6 +121,8 @@ public class ClassNode extends GraphNode implements Cloneable {
     if (o instanceof ClassNode) {
       ClassNode fs=(ClassNode)o;
       if ((fs.getClassDescriptor()!= cd) ||
+         (fs.getuid()!= uid) ||
+         (fs.getCid()!= cid) ||
           (fs.isSorted() != sorted) ||
           (fs.clone != this.clone) ||
           (fs.transTime != this.transTime)) {
@@ -110,8 +134,8 @@ public class ClassNode extends GraphNode implements Cloneable {
   }
 
   public int hashCode() {
-    return cd.hashCode()^Boolean.toString(sorted).hashCode()^Boolean.toString(clone).hashCode()^
-           transTime^flagStates.hashCode();
+    return cd.hashCode()^uid^cid^Boolean.toString(sorted).hashCode()^
+           Boolean.toString(clone).hashCode()^(int)transTime^flagStates.hashCode();
   }
 
   public String getLabel() {
@@ -135,10 +159,11 @@ public class ClassNode extends GraphNode implements Cloneable {
     ClassNode o = null;
     try {
       o = (ClassNode) super.clone();
-    } catch(CloneNotSupportedException e){
+    } catch(CloneNotSupportedException e) {
       e.printStackTrace();
     }
     o.uid = ClassNode.nodeID++;
+    o.cid = this.cid;
     o.clone = true;
     return o;
   }