fix bugs in memory model in multi-core version
[IRC.git] / Robust / src / Analysis / Scheduling / ObjectSimulator.java
1 package Analysis.Scheduling;
2
3 import Analysis.TaskStateAnalysis.FEdge;
4 import Analysis.TaskStateAnalysis.FlagState;
5 import IR.ClassDescriptor;
6
7 public class ObjectSimulator {
8   static int objid = 0;
9   
10   int oid;
11   ClassDescriptor cd;
12   FlagState currentFS;
13   boolean changed;
14   boolean shared;
15   boolean hold;
16   int version;
17   
18   // TODO, crack for KMeans
19   int counter;
20
21   public ObjectSimulator(ClassDescriptor cd, 
22                          FlagState currentFS) {
23     super();
24     this.oid = ObjectSimulator.objid++;
25     this.cd = cd;
26     this.currentFS = currentFS;
27     this.changed = true;
28     this.shared = false;
29     this.hold = false;
30     this.version = 0;
31     if(this.cd.getSymbol().equals("Cluster")) {
32       this.counter = 83 * 2 + 1; //102 * 2 + 1; //83 * 2 + 1;
33     } else {
34       this.counter = -1;
35     }
36   }
37
38   public void applyEdge(FEdge fedge) {
39     if(!currentFS.equals((FlagState)fedge.getTarget())) {
40       this.changed = true;
41       currentFS = (FlagState)fedge.getTarget();
42       if(this.counter > 0) {
43         //System.err.println(this.counter);
44         this.counter--;
45       }
46       if((this.cd.getSymbol().equals("Cluster")) && (this.counter == 0)) {
47         // go to end state
48         this.currentFS = new FlagState(this.cd);
49       }
50     } else {
51       this.changed = false;
52     }
53   }
54
55   public int getOid() {
56     return oid;
57   }
58
59   public ClassDescriptor getCd() {
60     return cd;
61   }
62
63   public FlagState getCurrentFS() {
64     return currentFS;
65   }
66
67   public boolean isChanged() {
68     return changed;
69   }
70
71   public void setCurrentFS(FlagState currentFS) {
72     changed = true;
73     this.currentFS = currentFS;
74   }
75
76   public boolean isHold() {
77     return hold;
78   }
79
80   public void setHold(boolean hold) {
81     this.hold = hold;
82   }
83
84   public boolean isShared() {
85     return shared;
86   }
87
88   public void setShared(boolean shared) {
89     this.shared = shared;
90   }
91
92   public int getVersion() {
93     return version;
94   }
95
96   public void increaseVersion() {
97     this.version++;
98   }
99 }