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;
59 protected Set<TempDescriptor> readyInVars;
60 protected Set<TempDescriptor> staticInVars;
61 protected Set<TempDescriptor> dynamicInVars;
63 protected Set<SESEandAgePair> staticInVarSrcs;
65 protected Hashtable<TempDescriptor, VariableSourceToken> staticInVar2src;
67 // get the oldest age of this task that other contexts
68 // have a static name for when tracking variables
69 protected Integer oldestAgeToTrack;
72 // a subset of the in-set variables that shouuld be traversed during
73 // the dynamic coarse grained conflict strategy, remember them here so
74 // buildcode can be dumb and just gen the traversals
75 protected Vector<TempDescriptor> inVarsForDynamicCoarseConflictResolution;
78 // scope info for this SESE
79 protected FlatMethod fmEnclosing;
80 protected MethodDescriptor mdEnclosing;
81 protected ClassDescriptor cdEnclosing;
83 // structures that allow SESE to appear as
84 // a normal method to code generation
85 protected FlatMethod fmBogus;
86 protected MethodDescriptor mdBogus;
88 // used during code generation to calculate an offset
89 // into the SESE-specific record, specifically to the
90 // first field in a sequence of pointers to other SESE
91 // records which is relevant to garbage collection
92 protected String firstDepRecField;
93 protected int numDepRecs;
96 public FlatSESEEnterNode( SESENode sn ) {
97 this.id = identifier++;
99 children = new HashSet<FlatSESEEnterNode>();
100 parents = new HashSet<FlatSESEEnterNode>();
101 localChildren = new HashSet<FlatSESEEnterNode>();
103 inVars = new HashSet<TempDescriptor>();
104 outVars = new HashSet<TempDescriptor>();
105 readyInVars = new HashSet<TempDescriptor>();
106 staticInVars = new HashSet<TempDescriptor>();
107 dynamicInVars = new HashSet<TempDescriptor>();
108 staticInVarSrcs = new HashSet<SESEandAgePair>();
109 oldestAgeToTrack = new Integer( 0 );
111 staticInVar2src = new Hashtable<TempDescriptor, VariableSourceToken>();
113 inVarsForDynamicCoarseConflictResolution = new Vector<TempDescriptor>();
120 isLeafSESE = ISLEAF_UNINIT;
123 isCallerProxySESE = false;
125 firstDepRecField = null;
129 public void rewriteUse() {
132 public void rewriteDef() {
135 public void setFlatExit( FlatSESEExitNode fsexn ) {
139 public FlatSESEExitNode getFlatExit() {
143 public void setIsMainSESE() {
147 public boolean getIsMainSESE() {
151 public void setIsCallerProxySESE() {
152 isCallerProxySESE = true;
155 public boolean getIsCallerProxySESE() {
156 return isCallerProxySESE;
160 return FKind.FlatSESEEnterNode;
163 public SESENode getTreeNode() {
167 public int getIdentifier() {
171 public String getPrettyIdentifier() {
172 if( treeNode != null && treeNode.getID() != null ) {
173 return treeNode.getID();
178 public String toString() {
179 return "sese "+getPrettyIdentifier()+" enter";
182 public String toPrettyString() {
183 return "sese "+getPrettyIdentifier()+getIdentifier();
187 public void mustTrackAtLeastAge( Integer age ) {
188 if( age > oldestAgeToTrack ) {
189 oldestAgeToTrack = new Integer( age );
193 public Integer getOldestAgeToTrack() {
194 return oldestAgeToTrack;
198 public void addParent( FlatSESEEnterNode parent ) {
199 parents.add( parent );
202 public Set<FlatSESEEnterNode> getParents() {
206 public void setLocalParent( FlatSESEEnterNode parent ) {
207 localParent = parent;
210 public FlatSESEEnterNode getLocalParent() {
214 public void addChild( FlatSESEEnterNode child ) {
215 children.add( child );
218 public void addChildren( Set<FlatSESEEnterNode> batch ) {
219 children.addAll( batch );
222 public Set<FlatSESEEnterNode> getChildren() {
226 public void addLocalChild( FlatSESEEnterNode child ) {
227 localChildren.add( child );
230 public Set<FlatSESEEnterNode> getLocalChildren() {
231 return localChildren;
236 public void addInVar( TempDescriptor td ) {
237 if (!inVars.contains(td))
241 public void addOutVar( TempDescriptor td ) {
245 public void addInVarSet( Set<TempDescriptor> s ) {
249 public void addOutVarSet( Set<TempDescriptor> s ) {
253 public Set<TempDescriptor> getInVarSet() {
257 Vector<TempDescriptor> vecinVars;
259 HashSet<TempDescriptor> paramset=new HashSet<TempDescriptor>();
260 paramset.addAll(inVars);
261 paramset.addAll(outVars);
262 vecinVars=new Vector<TempDescriptor>();
263 vecinVars.addAll(paramset);
266 public TempDescriptor getParameter(int i) {
267 if (vecinVars==null) {
270 return vecinVars.get(i);
273 public int numParameters() {
274 if (vecinVars==null) {
277 return vecinVars.size();
280 public Set<FlatNode> getNodeSet() {
281 HashSet<FlatNode> tovisit=new HashSet<FlatNode>();
282 HashSet<FlatNode> visited=new HashSet<FlatNode>();
284 while(!tovisit.isEmpty()) {
285 FlatNode fn=tovisit.iterator().next();
290 for(int i=0; i<fn.numNext(); i++) {
291 FlatNode nn=fn.getNext(i);
292 if (!visited.contains(nn))
300 public Set<TempDescriptor> getOutVarSet() {
304 public void addStaticInVarSrc( SESEandAgePair p ) {
305 staticInVarSrcs.add( p );
308 public Set<SESEandAgePair> getStaticInVarSrcs() {
309 return staticInVarSrcs;
312 public void addReadyInVar( TempDescriptor td ) {
313 readyInVars.add( td );
316 public Set<TempDescriptor> getReadyInVarSet() {
320 public void addStaticInVar( TempDescriptor td ) {
321 staticInVars.add( td );
324 public Set<TempDescriptor> getStaticInVarSet() {
328 public void putStaticInVar2src( TempDescriptor staticInVar,
329 VariableSourceToken vst ) {
330 staticInVar2src.put( staticInVar, vst );
333 public VariableSourceToken getStaticInVarSrc( TempDescriptor staticInVar ) {
334 return staticInVar2src.get( staticInVar );
337 public void addDynamicInVar( TempDescriptor td ) {
338 dynamicInVars.add( td );
341 public Set<TempDescriptor> getDynamicInVarSet() {
342 return dynamicInVars;
346 public void setfmEnclosing( FlatMethod fm ) { fmEnclosing = fm; }
347 public FlatMethod getfmEnclosing() { return fmEnclosing; }
349 public void setmdEnclosing( MethodDescriptor md ) { mdEnclosing = md; }
350 public MethodDescriptor getmdEnclosing() { return mdEnclosing; }
352 public void setcdEnclosing( ClassDescriptor cd ) { cdEnclosing = cd; }
353 public ClassDescriptor getcdEnclosing() { return cdEnclosing; }
355 public void setfmBogus( FlatMethod fm ) { fmBogus = fm; }
356 public FlatMethod getfmBogus() { return fmBogus; }
358 public void setmdBogus( MethodDescriptor md ) { mdBogus = md; }
359 public MethodDescriptor getmdBogus() { return mdBogus; }
361 public String getSESEmethodName() {
362 assert cdEnclosing != null;
363 assert mdBogus != null;
366 cdEnclosing.getSafeSymbol()+
367 mdBogus.getSafeSymbol()+
369 mdBogus.getSafeMethodDescriptor();
372 public String getSESErecordName() {
373 assert cdEnclosing != null;
374 assert mdBogus != null;
378 cdEnclosing.getSafeSymbol()+
379 mdBogus.getSafeSymbol()+
381 mdBogus.getSafeMethodDescriptor()+
385 public boolean equals( Object o ) {
390 if( !(o instanceof FlatSESEEnterNode) ) {
394 FlatSESEEnterNode fsen = (FlatSESEEnterNode) o;
395 return id == fsen.id;
398 public int hashCode() {
404 public void setFirstDepRecField( String field ) {
405 firstDepRecField = field;
408 public String getFirstDepRecField() {
409 return firstDepRecField;
412 public void incNumDepRecs() {
416 public int getNumDepRecs() {
420 public Vector<TempDescriptor> getInVarsForDynamicCoarseConflictResolution() {
421 return inVarsForDynamicCoarseConflictResolution;
424 public void addInVarForDynamicCoarseConflictResolution(TempDescriptor inVar) {
425 if (!inVarsForDynamicCoarseConflictResolution.contains(inVar))
426 inVarsForDynamicCoarseConflictResolution.add(inVar);
429 public void setIsLeafSESE( boolean isLeaf ) {
431 isLeafSESE = ISLEAF_TRUE;
433 isLeafSESE = ISLEAF_FALSE;
437 public boolean getIsLeafSESE() {
438 if( isLeafSESE == ISLEAF_UNINIT ) {
439 throw new Error( "isLeafSESE uninitialized" );
442 return isLeafSESE == ISLEAF_TRUE;