2 import java.util.HashSet;
3 import java.util.Hashtable;
5 import java.util.Vector;
6 import java.util.Iterator;
7 import java.util.Collection;
8 import Analysis.OoOJava.VariableSourceToken;
9 import Analysis.OoOJava.SESEandAgePair;
10 import Analysis.OwnershipAnalysis.HeapRegionNode;
11 import IR.ClassDescriptor;
12 import IR.FieldDescriptor;
13 import IR.MethodDescriptor;
14 import IR.TypeDescriptor;
15 import IR.Tree.SESENode;
17 public class FlatSESEEnterNode extends FlatNode {
19 // SESE class identifiers should be numbered
20 // sequentially from 0 to 1-(total # SESE's)
21 private static int identifier=0;
24 protected FlatSESEExitNode exit;
25 protected SESENode treeNode;
27 // a leaf tasks simply has no children, ever
28 protected static final int ISLEAF_UNINIT = 1;
29 protected static final int ISLEAF_FALSE = 2;
30 protected static final int ISLEAF_TRUE = 3;
31 protected int isLeafSESE;
33 // there is only one main sese that is implicit
34 // (spliced in by the compiler around whole program)
35 protected boolean isMainSESE;
37 // this is a useful static name for whichever task
38 // invoked the current local method context
39 protected boolean isCallerProxySESE;
41 // all children tasks, INCLUDING those that are reachable
43 protected Set<FlatSESEEnterNode> children;
45 // all possible parents
46 protected Set<FlatSESEEnterNode> parents;
48 // sometimes it is useful to know the locally defined
49 // parent or children of an SESE for various analysis,
50 // and by local it is one SESE nested within another
51 // in a single method context
52 protected Set<FlatSESEEnterNode> localChildren;
53 protected FlatSESEEnterNode localParent;
56 protected Set<TempDescriptor> inVars;
57 protected Set<TempDescriptor> outVars;
60 // for in-vars, classify them by source type to drive
61 // code gen for issuing this task
62 protected Set<TempDescriptor> readyInVars;
63 protected Set<TempDescriptor> staticInVars;
64 protected Set<TempDescriptor> dynamicInVars;
65 protected Set<SESEandAgePair> staticInVarSrcs;
66 protected Hashtable<TempDescriptor, VariableSourceToken> staticInVar2src;
68 // for out-vars, classify them by source type to drive
69 // code gen for when this task exits: if the exiting task
70 // has to assume the values from any of its children, it needs
71 // to know how to acquire those values before it can truly exit
72 protected Set<TempDescriptor> readyOutVars;
73 protected Set<TempDescriptor> staticOutVars;
74 protected Set<TempDescriptor> dynamicOutVars;
75 protected Set<SESEandAgePair> staticOutVarSrcs;
76 protected Hashtable<TempDescriptor, VariableSourceToken> staticOutVar2src;
80 // get the oldest age of this task that other contexts
81 // have a static name for when tracking variables
82 protected Integer oldestAgeToTrack;
85 // a subset of the in-set variables that shouuld be traversed during
86 // the dynamic coarse grained conflict strategy, remember them here so
87 // buildcode can be dumb and just gen the traversals
88 protected Vector<TempDescriptor> inVarsForDynamicCoarseConflictResolution;
91 // scope info for this SESE
92 protected FlatMethod fmEnclosing;
93 protected MethodDescriptor mdEnclosing;
94 protected ClassDescriptor cdEnclosing;
96 // structures that allow SESE to appear as
97 // a normal method to code generation
98 protected FlatMethod fmBogus;
99 protected MethodDescriptor mdBogus;
101 // used during code generation to calculate an offset
102 // into the SESE-specific record, specifically to the
103 // first field in a sequence of pointers to other SESE
104 // records which is relevant to garbage collection
105 protected String firstDepRecField;
106 protected int numDepRecs;
109 public FlatSESEEnterNode(SESENode sn) {
110 this.id = identifier++;
112 children = new HashSet<FlatSESEEnterNode>();
113 parents = new HashSet<FlatSESEEnterNode>();
114 localChildren = new HashSet<FlatSESEEnterNode>();
116 inVars = new HashSet<TempDescriptor>();
117 outVars = new HashSet<TempDescriptor>();
118 readyInVars = new HashSet<TempDescriptor>();
119 staticInVars = new HashSet<TempDescriptor>();
120 dynamicInVars = new HashSet<TempDescriptor>();
121 staticInVarSrcs = new HashSet<SESEandAgePair>();
122 readyOutVars = new HashSet<TempDescriptor>();
123 staticOutVars = new HashSet<TempDescriptor>();
124 dynamicOutVars = new HashSet<TempDescriptor>();
125 staticOutVarSrcs = new HashSet<SESEandAgePair>();
126 oldestAgeToTrack = new Integer(0);
128 staticInVar2src = new Hashtable<TempDescriptor, VariableSourceToken>();
129 staticOutVar2src = new Hashtable<TempDescriptor, VariableSourceToken>();
131 inVarsForDynamicCoarseConflictResolution = new Vector<TempDescriptor>();
138 isLeafSESE = ISLEAF_UNINIT;
141 isCallerProxySESE = false;
143 firstDepRecField = null;
147 public void rewriteUse() {
150 public void rewriteDef() {
153 public void setFlatExit(FlatSESEExitNode fsexn) {
157 public FlatSESEExitNode getFlatExit() {
161 public void setIsMainSESE() {
165 public boolean getIsMainSESE() {
169 public void setIsCallerProxySESE() {
170 isCallerProxySESE = true;
173 public boolean getIsCallerProxySESE() {
174 return isCallerProxySESE;
178 return FKind.FlatSESEEnterNode;
181 public SESENode getTreeNode() {
185 public int getIdentifier() {
189 public String getPrettyIdentifier() {
190 if(isCallerProxySESE) {
193 if( treeNode != null && treeNode.getID() != null ) {
194 return treeNode.getID();
199 public String toString() {
200 return "sese "+getPrettyIdentifier()+" enter";
203 public String toPrettyString() {
204 return "sese "+getPrettyIdentifier()+getIdentifier();
208 public void mustTrackAtLeastAge(Integer age) {
209 if( age > oldestAgeToTrack ) {
210 oldestAgeToTrack = new Integer(age);
214 public Integer getOldestAgeToTrack() {
215 return oldestAgeToTrack;
219 public void addParent(FlatSESEEnterNode parent) {
223 public Set<FlatSESEEnterNode> getParents() {
227 public void setLocalParent(FlatSESEEnterNode parent) {
228 localParent = parent;
231 public FlatSESEEnterNode getLocalParent() {
235 public void addChild(FlatSESEEnterNode child) {
239 public void addChildren(Set<FlatSESEEnterNode> batch) {
240 children.addAll(batch);
243 public Set<FlatSESEEnterNode> getChildren() {
247 public void addLocalChild(FlatSESEEnterNode child) {
248 localChildren.add(child);
251 public Set<FlatSESEEnterNode> getLocalChildren() {
252 return localChildren;
257 public void addInVar(TempDescriptor td) {
258 if (!inVars.contains(td))
262 public void addOutVar(TempDescriptor td) {
266 public void addInVarSet(Set<TempDescriptor> s) {
270 public void addOutVarSet(Set<TempDescriptor> s) {
274 public Set<TempDescriptor> getInVarSet() {
278 Vector<TempDescriptor> vecinVars;
280 HashSet<TempDescriptor> paramset=new HashSet<TempDescriptor>();
281 paramset.addAll(inVars);
282 paramset.addAll(outVars);
283 vecinVars=new Vector<TempDescriptor>();
284 vecinVars.addAll(paramset);
287 public TempDescriptor getParameter(int i) {
288 if (vecinVars==null) {
291 return vecinVars.get(i);
294 public int numParameters() {
295 if (vecinVars==null) {
298 return vecinVars.size();
301 public Set<FlatNode> getNodeSet() {
302 HashSet<FlatNode> tovisit=new HashSet<FlatNode>();
303 HashSet<FlatNode> visited=new HashSet<FlatNode>();
305 while(!tovisit.isEmpty()) {
306 FlatNode fn=tovisit.iterator().next();
311 for(int i=0; i<fn.numNext(); i++) {
312 FlatNode nn=fn.getNext(i);
313 if (!visited.contains(nn))
321 public Set<TempDescriptor> getOutVarSet() {
325 public void addStaticInVarSrc(SESEandAgePair p) {
326 staticInVarSrcs.add(p);
329 public Set<SESEandAgePair> getStaticInVarSrcs() {
330 return staticInVarSrcs;
333 public void addReadyInVar(TempDescriptor td) {
337 public Set<TempDescriptor> getReadyInVarSet() {
341 public void addStaticInVar(TempDescriptor td) {
342 staticInVars.add(td);
345 public Set<TempDescriptor> getStaticInVarSet() {
349 public void putStaticInVar2src(TempDescriptor staticInVar,
350 VariableSourceToken vst) {
351 staticInVar2src.put(staticInVar, vst);
354 public VariableSourceToken getStaticInVarSrc(TempDescriptor staticInVar) {
355 return staticInVar2src.get(staticInVar);
358 public void addDynamicInVar(TempDescriptor td) {
359 dynamicInVars.add(td);
362 public Set<TempDescriptor> getDynamicInVarSet() {
363 return dynamicInVars;
368 public void addReadyOutVar(TempDescriptor td) {
369 readyOutVars.add(td);
372 public Set<TempDescriptor> getReadyOutVarSet() {
376 public void addStaticOutVarSrc(SESEandAgePair p) {
377 staticOutVarSrcs.add(p);
380 public Set<SESEandAgePair> getStaticOutVarSrcs() {
381 return staticOutVarSrcs;
384 public void addStaticOutVar(TempDescriptor td) {
385 staticOutVars.add(td);
388 public Set<TempDescriptor> getStaticOutVarSet() {
389 return staticOutVars;
392 public void putStaticOutVar2src(TempDescriptor staticOutVar,
393 VariableSourceToken vst) {
394 staticOutVar2src.put(staticOutVar, vst);
397 public VariableSourceToken getStaticOutVarSrc(TempDescriptor staticOutVar) {
398 return staticOutVar2src.get(staticOutVar);
401 public void addDynamicOutVar(TempDescriptor td) {
402 dynamicOutVars.add(td);
405 public Set<TempDescriptor> getDynamicOutVarSet() {
406 return dynamicOutVars;
412 public void setfmEnclosing(FlatMethod fm) {
415 public FlatMethod getfmEnclosing() {
419 public void setmdEnclosing(MethodDescriptor md) {
422 public MethodDescriptor getmdEnclosing() {
426 public void setcdEnclosing(ClassDescriptor cd) {
429 public ClassDescriptor getcdEnclosing() {
433 public void setfmBogus(FlatMethod fm) {
436 public FlatMethod getfmBogus() {
440 public void setmdBogus(MethodDescriptor md) {
443 public MethodDescriptor getmdBogus() {
447 public String getSESEmethodName() {
448 assert cdEnclosing != null;
449 assert mdBogus != null;
452 cdEnclosing.getSafeSymbol()+
453 mdBogus.getSafeSymbol()+
455 mdBogus.getSafeMethodDescriptor();
458 public String getSESErecordName() {
459 assert cdEnclosing != null;
460 assert mdBogus != null;
464 cdEnclosing.getSafeSymbol()+
465 mdBogus.getSafeSymbol()+
467 mdBogus.getSafeMethodDescriptor()+
471 public boolean equals(Object o) {
476 if( !(o instanceof FlatSESEEnterNode) ) {
480 FlatSESEEnterNode fsen = (FlatSESEEnterNode) o;
481 return id == fsen.id;
484 public int hashCode() {
490 public void setFirstDepRecField(String field) {
491 firstDepRecField = field;
494 public String getFirstDepRecField() {
495 return firstDepRecField;
498 public void incNumDepRecs() {
502 public int getNumDepRecs() {
506 public Vector<TempDescriptor> getInVarsForDynamicCoarseConflictResolution() {
507 return inVarsForDynamicCoarseConflictResolution;
510 public void addInVarForDynamicCoarseConflictResolution(TempDescriptor inVar) {
511 if (!inVarsForDynamicCoarseConflictResolution.contains(inVar))
512 inVarsForDynamicCoarseConflictResolution.add(inVar);
515 public void setIsLeafSESE(boolean isLeaf) {
517 isLeafSESE = ISLEAF_TRUE;
519 isLeafSESE = ISLEAF_FALSE;
523 public boolean getIsLeafSESE() {
524 if( isLeafSESE == ISLEAF_UNINIT ) {
525 throw new Error("isLeafSESE uninitialized");
528 return isLeafSESE == ISLEAF_TRUE;