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;
26 protected Integer oldestAgeToTrack;
28 // a leaf tasks simply has no children, ever
29 protected static final int ISLEAF_UNINIT = 1;
30 protected static final int ISLEAF_FALSE = 2;
31 protected static final int ISLEAF_TRUE = 3;
32 protected int isLeafSESE;
34 // there is only one main sese that is implicit
35 // (spliced in by the compiler around whole program)
36 protected boolean isMainSESE;
38 // all children tasks, INCLUDING those that are reachable
40 protected Set<FlatSESEEnterNode> children;
42 // all possible parents
43 protected Set<FlatSESEEnterNode> parents;
45 // sometimes it is useful to know the locally defined
46 // parent or children of an SESE for various analysis,
47 // and by local it is one SESE nested within another
48 // in a single method context
49 protected Set<FlatSESEEnterNode> localChildren;
50 protected FlatSESEEnterNode localParent;
53 protected Set<TempDescriptor> inVars;
54 protected Set<TempDescriptor> outVars;
56 protected Set<SESEandAgePair> needStaticNameInCode;
58 protected Set<SESEandAgePair> staticInVarSrcs;
60 protected Set<TempDescriptor> readyInVars;
61 protected Set<TempDescriptor> staticInVars;
62 protected Set<TempDescriptor> dynamicInVars;
64 protected Set<TempDescriptor> dynamicVars;
66 protected Hashtable<TempDescriptor, VariableSourceToken> staticInVar2src;
69 // a subset of the in-set variables that shouuld be traversed during
70 // the dynamic coarse grained conflict strategy, remember them here so
71 // buildcode can be dumb and just gen the traversals
72 protected Vector<TempDescriptor> inVarsForDynamicCoarseConflictResolution;
74 // scope info for this SESE
75 protected FlatMethod fmEnclosing;
76 protected MethodDescriptor mdEnclosing;
77 protected ClassDescriptor cdEnclosing;
79 // structures that allow SESE to appear as
80 // a normal method to code generation
81 protected FlatMethod fmBogus;
82 protected MethodDescriptor mdBogus;
84 // used during code generation to calculate an offset
85 // into the SESE-specific record, specifically to the
86 // first field in a sequence of pointers to other SESE
87 // records which is relevant to garbage collection
88 protected String firstDepRecField;
89 protected int numDepRecs;
92 public FlatSESEEnterNode( SESENode sn ) {
93 this.id = identifier++;
95 oldestAgeToTrack = new Integer( 0 );
96 children = new HashSet<FlatSESEEnterNode>();
97 parents = new HashSet<FlatSESEEnterNode>();
98 localChildren = new HashSet<FlatSESEEnterNode>();
100 inVars = new HashSet<TempDescriptor>();
101 outVars = new HashSet<TempDescriptor>();
102 needStaticNameInCode = new HashSet<SESEandAgePair>();
103 staticInVarSrcs = new HashSet<SESEandAgePair>();
104 readyInVars = new HashSet<TempDescriptor>();
105 staticInVars = new HashSet<TempDescriptor>();
106 dynamicInVars = new HashSet<TempDescriptor>();
107 dynamicVars = new HashSet<TempDescriptor>();
109 inVarsForDynamicCoarseConflictResolution = new Vector<TempDescriptor>();
111 staticInVar2src = new Hashtable<TempDescriptor, VariableSourceToken>();
117 isLeafSESE = ISLEAF_UNINIT;
121 firstDepRecField = null;
125 public void rewriteUse() {
128 public void rewriteDef() {
131 public void setFlatExit( FlatSESEExitNode fsexn ) {
135 public FlatSESEExitNode getFlatExit() {
139 public void setIsMainSESE() {
143 public boolean getIsMainSESE() {
148 return FKind.FlatSESEEnterNode;
151 public SESENode getTreeNode() {
155 public int getIdentifier() {
159 public String getPrettyIdentifier() {
160 if( treeNode.getID() != null ) {
161 return treeNode.getID();
166 public String toString() {
167 return "sese "+getPrettyIdentifier()+" enter";
170 public String toPrettyString() {
171 return "sese "+getPrettyIdentifier()+getIdentifier();
176 public void addParent( FlatSESEEnterNode parent ) {
177 parents.add( parent );
180 public Set<FlatSESEEnterNode> getParents() {
184 public void setLocalParent( FlatSESEEnterNode parent ) {
185 localParent = parent;
188 public FlatSESEEnterNode getLocalParent() {
192 public void addChild( FlatSESEEnterNode child ) {
193 children.add( child );
196 public void addChildren( Set<FlatSESEEnterNode> batch ) {
197 children.addAll( batch );
200 public Set<FlatSESEEnterNode> getChildren() {
204 public void addLocalChild( FlatSESEEnterNode child ) {
205 localChildren.add( child );
208 public Set<FlatSESEEnterNode> getLocalChildren() {
209 return localChildren;
214 public void addInVar( TempDescriptor td ) {
215 if (!inVars.contains(td))
219 public void addOutVar( TempDescriptor td ) {
223 public void addInVarSet( Set<TempDescriptor> s ) {
227 public void addOutVarSet( Set<TempDescriptor> s ) {
231 public Set<TempDescriptor> getInVarSet() {
235 Vector<TempDescriptor> vecinVars;
237 HashSet<TempDescriptor> paramset=new HashSet<TempDescriptor>();
238 paramset.addAll(inVars);
239 paramset.addAll(outVars);
240 vecinVars=new Vector<TempDescriptor>();
241 vecinVars.addAll(paramset);
244 public TempDescriptor getParameter(int i) {
245 if (vecinVars==null) {
248 return vecinVars.get(i);
251 public int numParameters() {
252 if (vecinVars==null) {
255 return vecinVars.size();
258 public Set<FlatNode> getNodeSet() {
259 HashSet<FlatNode> tovisit=new HashSet<FlatNode>();
260 HashSet<FlatNode> visited=new HashSet<FlatNode>();
262 while(!tovisit.isEmpty()) {
263 FlatNode fn=tovisit.iterator().next();
268 for(int i=0; i<fn.numNext(); i++) {
269 FlatNode nn=fn.getNext(i);
270 if (!visited.contains(nn))
278 public Set<TempDescriptor> getOutVarSet() {
282 public void addNeededStaticName( SESEandAgePair p ) {
283 needStaticNameInCode.add( p );
286 public Set<SESEandAgePair> getNeededStaticNames() {
287 return needStaticNameInCode;
290 public void addStaticInVarSrc( SESEandAgePair p ) {
291 staticInVarSrcs.add( p );
294 public Set<SESEandAgePair> getStaticInVarSrcs() {
295 return staticInVarSrcs;
298 public void addReadyInVar( TempDescriptor td ) {
299 readyInVars.add( td );
302 public Set<TempDescriptor> getReadyInVarSet() {
306 public void addStaticInVar( TempDescriptor td ) {
307 staticInVars.add( td );
310 public Set<TempDescriptor> getStaticInVarSet() {
314 public void putStaticInVar2src( TempDescriptor staticInVar,
315 VariableSourceToken vst ) {
316 staticInVar2src.put( staticInVar, vst );
319 public VariableSourceToken getStaticInVarSrc( TempDescriptor staticInVar ) {
320 return staticInVar2src.get( staticInVar );
323 public void addDynamicInVar( TempDescriptor td ) {
324 dynamicInVars.add( td );
327 public Set<TempDescriptor> getDynamicInVarSet() {
328 return dynamicInVars;
331 public void addDynamicVar( TempDescriptor td ) {
332 dynamicVars.add( td );
335 public Set<TempDescriptor> getDynamicVarSet() {
339 public void mustTrackAtLeastAge( Integer age ) {
340 if( age > oldestAgeToTrack ) {
341 oldestAgeToTrack = new Integer( age );
345 public Integer getOldestAgeToTrack() {
346 return oldestAgeToTrack;
349 public void setfmEnclosing( FlatMethod fm ) { fmEnclosing = fm; }
350 public FlatMethod getfmEnclosing() { return fmEnclosing; }
352 public void setmdEnclosing( MethodDescriptor md ) { mdEnclosing = md; }
353 public MethodDescriptor getmdEnclosing() { return mdEnclosing; }
355 public void setcdEnclosing( ClassDescriptor cd ) { cdEnclosing = cd; }
356 public ClassDescriptor getcdEnclosing() { return cdEnclosing; }
358 public void setfmBogus( FlatMethod fm ) { fmBogus = fm; }
359 public FlatMethod getfmBogus() { return fmBogus; }
361 public void setmdBogus( MethodDescriptor md ) { mdBogus = md; }
362 public MethodDescriptor getmdBogus() { return mdBogus; }
364 public String getSESEmethodName() {
365 assert cdEnclosing != null;
366 assert mdBogus != null;
369 cdEnclosing.getSafeSymbol()+
370 mdBogus.getSafeSymbol()+
372 mdBogus.getSafeMethodDescriptor();
375 public String getSESErecordName() {
376 assert cdEnclosing != null;
377 assert mdBogus != null;
381 cdEnclosing.getSafeSymbol()+
382 mdBogus.getSafeSymbol()+
384 mdBogus.getSafeMethodDescriptor()+
388 public boolean equals( Object o ) {
393 if( !(o instanceof FlatSESEEnterNode) ) {
397 FlatSESEEnterNode fsen = (FlatSESEEnterNode) o;
398 return id == fsen.id;
401 public int hashCode() {
407 public void setFirstDepRecField( String field ) {
408 firstDepRecField = field;
411 public String getFirstDepRecField() {
412 return firstDepRecField;
415 public void incNumDepRecs() {
419 public int getNumDepRecs() {
423 public Vector<TempDescriptor> getInVarsForDynamicCoarseConflictResolution() {
424 return inVarsForDynamicCoarseConflictResolution;
427 public void addInVarForDynamicCoarseConflictResolution(TempDescriptor inVar) {
428 if (!inVarsForDynamicCoarseConflictResolution.contains(inVar))
429 inVarsForDynamicCoarseConflictResolution.add(inVar);
432 public void setIsLeafSESE( boolean isLeaf ) {
434 isLeafSESE = ISLEAF_TRUE;
436 isLeafSESE = ISLEAF_FALSE;
440 public boolean getIsLeafSESE() {
441 if( isLeafSESE == ISLEAF_UNINIT ) {
442 throw new Error( "isLeafSESE uninitialized" );
445 return isLeafSESE == ISLEAF_TRUE;