Shrink the size of the final binary. If it is too large it will have problem executi...
[IRC.git] / Robust / src / IR / State.java
1 package IR;
2 import IR.Tree.*;
3 import IR.Flat.*;
4 import IR.*;
5 import Util.Lattice;
6
7 import java.util.*;
8 import Analysis.TaskStateAnalysis.*;
9
10 public class State {
11
12     public int lines;
13   public State() {
14     this.classes=new SymbolTable();
15     this.tasks=new SymbolTable();
16     this.sclasses=new SymbolTable();
17     this.treemethodmap=new Hashtable();
18     this.flatmethodmap=new Hashtable();
19     this.genAllMethods = true;
20     this.methods2gen = new SymbolTable();
21     this.parsetrees=new HashSet();
22     this.arraytypes=new HashSet();
23     this.arraytonumber=new Hashtable();
24     this.tagmap=new Hashtable();
25     this.selfloops=new HashSet();
26     this.excprefetch=new HashSet();
27     this.classpath=new Vector();
28     this.cd2locationOrderMap=new Hashtable();
29     this.lines=0;
30   }
31
32   public void addParseNode(ParseNode parsetree) {
33     parsetrees.add(parsetree);
34   }
35
36   public void storeAnalysisResult(Hashtable<ClassDescriptor, Hashtable<FlagState, Set<OptionalTaskDescriptor>>> analysisresults) {
37     this.analysisresults=analysisresults;
38   }
39
40   public Hashtable<ClassDescriptor, Hashtable<FlagState, Set<OptionalTaskDescriptor>>> getAnalysisResult() {
41     return analysisresults;
42   }
43
44
45   public void storeOptionalTaskDescriptors(Hashtable<ClassDescriptor, Hashtable<OptionalTaskDescriptor, OptionalTaskDescriptor>> optionaltaskdescriptors) {
46     this.optionaltaskdescriptors=optionaltaskdescriptors;
47   }
48
49   public Hashtable<ClassDescriptor, Hashtable<OptionalTaskDescriptor, OptionalTaskDescriptor>> getOptionalTaskDescriptors() {
50     return optionaltaskdescriptors;
51   }
52
53
54   /** Boolean flag which indicates whether compiler is compiling a task-based
55    * program. */
56   public boolean POINTER=false;
57   public boolean COREPROF=false;
58   public boolean WEBINTERFACE=false;
59   public boolean MINIMIZE=false;
60   public boolean TASK=false;
61   public boolean FASTCHECK=false;
62   public boolean PREFETCH=false;
63   public boolean TASKSTATE=false;
64   public boolean TAGSTATE=false;
65   public boolean FLATIRGRAPH=false;
66   public boolean FLATIRGRAPHTASKS=false;
67   public boolean FLATIRGRAPHUSERMETHODS=false;
68   public boolean FLATIRGRAPHLIBMETHODS=false;
69   public boolean KEEP_RG_FOR_ALL_PROGRAM_POINTS=false;
70   public boolean OWNERSHIP=false;
71   public int OWNERSHIPALLOCDEPTH=3;
72   public boolean OWNERSHIPWRITEDOTS=false;
73   public boolean OWNERSHIPWRITEALL=false;
74   public String OWNERSHIPALIASFILE=null;
75   public boolean OWNERSHIPALIASTAB=false;
76   public int OWNERSHIPDEBUGCALLCOUNT=0;
77   public String OWNERSHIPDEBUGCALLEE=null;
78   public String OWNERSHIPDEBUGCALLER=null;
79
80   
81   public boolean DISJOINT=false;
82
83   public int DISJOINTALLOCDEPTH=1;
84   public boolean DISJOINTRELEASEMODE=false;
85   public boolean DISJOINTDETERMINISM=false;
86
87   public boolean DISJOINTDVISITSTACK=true;
88   public boolean DISJOINTDVISITPQUE=false;
89   public boolean DISJOINTDVISITSTACKEESONTOP=false;
90
91   public boolean DISJOINTWRITEDOTS=false;
92   public boolean DISJOINTWRITEALL=false;
93   public boolean DISJOINTWRITEIHMS=false;
94   public boolean DISJOINTWRITEINITCONTEXTS=false;
95
96   public String DISJOINTALIASFILE=null;
97   public boolean DISJOINTALIASTAB=false;
98
99   public String DISJOINTDEBUGCALLEE=null;
100   public String DISJOINTDEBUGCALLER=null;
101   public int DISJOINTDEBUGCALLVISITTOSTART=0;
102   public int DISJOINTDEBUGCALLNUMVISITS=0;
103   public boolean DISJOINTDEBUGCALLSTOPAFTER=false;
104
105   public String DISJOINTSNAPSYMBOL=null;
106   public int DISJOINTSNAPVISITTOSTART=0;
107   public int DISJOINTSNAPNUMVISITS=0;
108   public boolean DISJOINTSNAPSTOPAFTER=false;
109
110   public boolean DISJOINTDEBUGSCHEDULING=false;
111
112   public boolean OOOJAVA=false;
113   public boolean OOODEBUG=false;
114   public boolean RCR=false;
115   public boolean RCR_DEBUG=false;
116   public boolean RCR_DEBUG_VERBOSE=false;
117   public boolean NOSTALLTR=false;
118   
119   //SSJava
120   public boolean SSJAVA=false;
121
122
123   public boolean OPTIONAL=false;
124   public boolean NOLOOP=false;
125   public boolean ARRAYPAD=false;
126   public boolean THREAD=false;
127   public boolean CONSCHECK=false;
128   public boolean INSTRUCTIONFAILURE=false;
129   public int OOO_NUMCORES=0;
130   public int OOO_MAXSESEAGE=0;
131   public boolean METHODEFFECTS=false;
132   public static double TRUEPROB=0.8;
133   public static boolean PRINTFLAT=false;
134   
135   //DSM options
136   public boolean DSM=false;
137   public boolean DSMTASK=false;
138   public static boolean ABORTREADERS=false;
139
140   // Recovery Stats Options
141   public boolean DSMRECOVERYSTATS=false;
142   //STM options
143   public boolean EVENTMONITOR=false;
144   public static boolean STMARRAY=false;
145   public static boolean SINGLETM=false;
146   public static boolean READSET=false;
147   public boolean SANDBOX=false;
148   public boolean DCOPTS=false;
149   public boolean DELAYCOMP=false;
150   public boolean DUALVIEW=false;
151   public boolean HYBRID=false;
152   
153   // Bamboo options
154   public boolean MULTICORE=false;
155   public boolean MULTICOREGC=false;
156   public boolean BAMBOOCOMPILETIME = false;
157   public boolean ARRAYBOUNDARYCHECK=true;
158   public boolean RAW=false;
159   public boolean SCHEDULING=false;
160   public boolean USEPROFILE=false;
161   public static boolean PRINTSCHEDULING=false;
162   public static boolean PRINTSCHEDULESIM=false;
163   public static boolean PRINTCRITICALPATH=false;
164   public int CORENUM = 1;
165   public int CORENUM4GC = 0;
166   public String profilename = null;
167   public String outputdir = "/scratch/";
168   // MGC options
169   public boolean MGC=false;
170   
171   //Other options
172   public String structfile;
173   public String main;
174   public boolean INLINEATOMIC=false;
175   public int inlineatomicdepth;
176   public HashSet selfloops;
177   public HashSet excprefetch;
178   public Vector classpath;
179   public SymbolTable classes;
180   public SymbolTable tasks;
181   public SymbolTable sclasses; // table of classes with static field/blocks
182   public Set parsetrees;
183   public Hashtable treemethodmap;
184   public Hashtable flatmethodmap;
185   SymbolTable methods2gen;
186   boolean genAllMethods;
187   private HashSet arraytypes;
188   public Hashtable arraytonumber;
189   private int numclasses=1; // start from 1 instead of 0 for multicore gc
190   private int numinterfaces = 0;
191   private int numtasks=0;
192   private int numstaticblocks=0;
193   private int arraycount=0;
194   public Hashtable cd2locationOrderMap;
195   public boolean OPTIMIZE=false;
196
197   private Hashtable<ClassDescriptor, Hashtable<OptionalTaskDescriptor, OptionalTaskDescriptor>> optionaltaskdescriptors;
198   private Hashtable<ClassDescriptor, Hashtable<FlagState, Set<OptionalTaskDescriptor>>> analysisresults;
199
200   private Hashtable tagmap;
201   private int numtags=0;
202
203   public void addArrayType(TypeDescriptor td) {
204     if (!arraytypes.contains(td)) {
205       arraytypes.add(td);
206       arraytonumber.put(td,new Integer(arraycount++));
207     }
208   }
209
210   public Iterator getArrayIterator() {
211     return arraytypes.iterator();
212   }
213
214   public int getTagId(TagDescriptor tag) {
215     if (tagmap.containsKey(tag)) {
216       return ((Integer) tagmap.get(tag)).intValue();
217     } else {
218       tagmap.put(tag, new Integer(numtags));
219       return numtags++;
220     }
221   }
222
223   public int getArrayNumber(TypeDescriptor td) {
224     if (arraytonumber.containsKey(td))
225       return ((Integer)arraytonumber.get(td)).intValue();
226     else return -1;
227   }
228
229   public int numArrays() {
230     return arraytypes.size();
231   }
232
233   public static TypeDescriptor getTypeDescriptor(int t) {
234     TypeDescriptor td=new TypeDescriptor(t);
235     return td;
236   }
237
238   public static TypeDescriptor getTypeDescriptor(NameDescriptor n) {
239     TypeDescriptor td=new TypeDescriptor(n);
240     return td;
241   }
242
243   public void addClass(ClassDescriptor tdn) {
244     if (classes.contains(tdn.getSymbol()))
245       throw new Error("Class "+tdn.getSymbol()+" defined twice");
246     classes.add(tdn);
247     if(tdn.isInterface()) {
248       numinterfaces++;
249     } else {
250       numclasses++;
251     }
252     if((tdn.numstaticfields != 0) || (tdn.numstaticblocks != 0)) {
253       sclasses.add(tdn);
254     }
255   }
256   
257   public void setGenAllMethods(boolean flag) {
258     this.genAllMethods = flag;
259   }
260   
261   public void addMethod2gen(MethodDescriptor md) {
262     if(this.genAllMethods) {
263       throw new Error("The state.genAllMethods is TRUE, do not need to check methods to genenrate");
264     }
265     this.methods2gen.add(md);
266   }
267   
268   public SymbolTable getMethod2gen() {
269     return this.methods2gen;
270   }
271   
272   public int numClasses() {
273     return numclasses;
274   }
275   
276   public int numInterfaces() {
277     return numinterfaces;
278   }
279   
280   public int numStaticBlocks() {
281     return numstaticblocks;
282   }
283
284   public BlockNode getMethodBody(MethodDescriptor md) {
285     return (BlockNode)treemethodmap.get(md);
286   }
287
288   public BlockNode getMethodBody(TaskDescriptor td) {
289     return (BlockNode)treemethodmap.get(td);
290   }
291
292   public SymbolTable getClassSymbolTable() {
293     return classes;
294   }
295
296   public SymbolTable getTaskSymbolTable() {
297     return tasks;
298   }
299   
300   public SymbolTable getSClassSymbolTable() {
301     return sclasses;
302   }
303
304   /** Returns Flat IR representation of MethodDescriptor md. */
305
306   public FlatMethod getMethodFlat(MethodDescriptor md) {
307     return (FlatMethod)flatmethodmap.get(md);
308   }
309
310   /** Returns Flat IR representation of TaskDescriptor td. */
311
312   public FlatMethod getMethodFlat(TaskDescriptor td) {
313     return (FlatMethod)flatmethodmap.get(td);
314   }
315
316   // The descriptor is either a method or task desc
317   // and should call one of the above methods
318   public FlatMethod getMethodFlat(Descriptor d) {
319     FlatMethod fm;
320     if( d instanceof MethodDescriptor ) {
321       fm = getMethodFlat( (MethodDescriptor) d);
322     } else {
323       assert d instanceof TaskDescriptor;
324       fm = getMethodFlat( (TaskDescriptor) d);
325     }
326     return fm;
327   }
328
329   public void addTreeCode(MethodDescriptor md, BlockNode bn) {
330     treemethodmap.put(md,bn);
331   }
332
333   public void addTreeCode(TaskDescriptor td, BlockNode bn) {
334     treemethodmap.put(td,bn);
335   }
336
337   public void addFlatCode(MethodDescriptor md, FlatMethod bn) {
338     flatmethodmap.put(md,bn);
339   }
340
341   public void addFlatCode(TaskDescriptor td, FlatMethod bn) {
342     flatmethodmap.put(td,bn);
343   }
344
345   public void addTask(TaskDescriptor td) {
346     if (tasks.contains(td.getSymbol()))
347       throw new Error("Task "+td.getSymbol()+" defined twice");
348     tasks.add(td);
349     numtasks++;
350   }
351   
352   public void addLocationOrder(ClassDescriptor cd, Lattice order){
353     cd2locationOrderMap.put(cd,order);
354   }
355   
356   public Hashtable getCd2LocationOrder(){
357     return cd2locationOrderMap;
358   }
359   
360 }