2 import java.util.HashSet;
3 import java.util.Hashtable;
5 import java.util.Vector;
7 import Analysis.MLP.SESEEffectsKey;
8 import Analysis.MLP.SESEEffectsSet;
9 import Analysis.MLP.SESEandAgePair;
10 import Analysis.MLP.VariableSourceToken;
11 import Analysis.OwnershipAnalysis.HeapRegionNode;
12 import IR.ClassDescriptor;
13 import IR.FieldDescriptor;
14 import IR.MethodDescriptor;
15 import IR.TypeDescriptor;
16 import IR.Tree.SESENode;
18 public class FlatSESEEnterNode extends FlatNode {
20 // SESE class identifiers should be numbered
21 // sequentially from 0 to 1-(total # SESE's)
22 private static int identifier=0;
25 protected FlatSESEExitNode exit;
26 protected SESENode treeNode;
27 protected FlatSESEEnterNode parent;
28 protected Integer oldestAgeToTrack;
29 protected boolean isCallerSESEplaceholder;
31 protected Set<FlatSESEEnterNode> children;
33 protected Set<TempDescriptor> inVars;
34 protected Set<TempDescriptor> outVars;
36 protected Set<SESEandAgePair> needStaticNameInCode;
38 protected Set<SESEandAgePair> staticInVarSrcs;
40 protected Set<TempDescriptor> readyInVars;
41 protected Set<TempDescriptor> staticInVars;
42 protected Set<TempDescriptor> dynamicInVars;
44 protected Set<TempDescriptor> dynamicVars;
46 protected Hashtable<TempDescriptor, VariableSourceToken> staticInVar2src;
48 private SESEEffectsSet seseEffectsSet;
50 // a subset of the in-set variables that shouuld be traversed during
51 // the dynamic coarse grained conflict strategy, remember them here so
52 // buildcode can be dumb and just gen the traversals
53 protected Set<TempDescriptor> inVarsForDynamicCoarseConflictResolution;
55 // scope info for this SESE
56 protected FlatMethod fmEnclosing;
57 protected MethodDescriptor mdEnclosing;
58 protected ClassDescriptor cdEnclosing;
60 // structures that allow SESE to appear as
61 // a normal method to code generation
62 protected FlatMethod fmBogus;
63 protected MethodDescriptor mdBogus;
65 // used during code generation to calculate an offset
66 // into the SESE-specific record, specifically to the
67 // first field in a sequence of pointers to other SESE
68 // records which is relevant to garbage collection
69 protected String firstDepRecField;
70 protected int numDepRecs;
73 public FlatSESEEnterNode( SESENode sn ) {
74 this.id = identifier++;
77 oldestAgeToTrack = new Integer( 0 );
79 children = new HashSet<FlatSESEEnterNode>();
80 inVars = new HashSet<TempDescriptor>();
81 outVars = new HashSet<TempDescriptor>();
82 needStaticNameInCode = new HashSet<SESEandAgePair>();
83 staticInVarSrcs = new HashSet<SESEandAgePair>();
84 readyInVars = new HashSet<TempDescriptor>();
85 staticInVars = new HashSet<TempDescriptor>();
86 dynamicInVars = new HashSet<TempDescriptor>();
87 dynamicVars = new HashSet<TempDescriptor>();
89 inVarsForDynamicCoarseConflictResolution = new HashSet<TempDescriptor>();
91 staticInVar2src = new Hashtable<TempDescriptor, VariableSourceToken>();
93 seseEffectsSet = new SESEEffectsSet();
99 isCallerSESEplaceholder = false;
101 firstDepRecField = null;
105 public void rewriteUse() {
108 public void rewriteDef() {
111 public void setFlatExit( FlatSESEExitNode fsexn ) {
115 public FlatSESEExitNode getFlatExit() {
120 return FKind.FlatSESEEnterNode;
123 public SESENode getTreeNode() {
127 public int getIdentifier() {
131 public String getPrettyIdentifier() {
132 if( treeNode.getID() != null ) {
133 return treeNode.getID();
138 public String toString() {
139 return "sese "+getPrettyIdentifier()+" enter";
142 public String toPrettyString() {
143 return "sese "+getPrettyIdentifier()+getIdentifier();
146 public void setParent( FlatSESEEnterNode parent ) {
147 this.parent = parent;
150 public FlatSESEEnterNode getParent() {
154 public void addChild( FlatSESEEnterNode child ) {
155 children.add( child );
158 public Set<FlatSESEEnterNode> getChildren() {
162 public void addInVar( TempDescriptor td ) {
166 public void addOutVar( TempDescriptor td ) {
170 public void addInVarSet( Set<TempDescriptor> s ) {
174 public void addOutVarSet( Set<TempDescriptor> s ) {
178 public Set<TempDescriptor> getInVarSet() {
182 Vector<TempDescriptor> vecinVars;
184 HashSet<TempDescriptor> paramset=new HashSet<TempDescriptor>();
185 paramset.addAll(inVars);
186 paramset.addAll(outVars);
187 vecinVars=new Vector<TempDescriptor>();
188 vecinVars.addAll(paramset);
191 public TempDescriptor getParameter(int i) {
192 if (vecinVars==null) {
195 return vecinVars.get(i);
198 public int numParameters() {
199 if (vecinVars==null) {
202 return vecinVars.size();
205 public Set<FlatNode> getNodeSet() {
206 HashSet<FlatNode> tovisit=new HashSet<FlatNode>();
207 HashSet<FlatNode> visited=new HashSet<FlatNode>();
209 while(!tovisit.isEmpty()) {
210 FlatNode fn=tovisit.iterator().next();
215 for(int i=0; i<fn.numNext(); i++) {
216 FlatNode nn=fn.getNext(i);
217 if (!visited.contains(nn))
225 public Set<TempDescriptor> getOutVarSet() {
229 public void addNeededStaticName( SESEandAgePair p ) {
230 needStaticNameInCode.add( p );
233 public Set<SESEandAgePair> getNeededStaticNames() {
234 return needStaticNameInCode;
237 public void addStaticInVarSrc( SESEandAgePair p ) {
238 staticInVarSrcs.add( p );
241 public Set<SESEandAgePair> getStaticInVarSrcs() {
242 return staticInVarSrcs;
245 public void addReadyInVar( TempDescriptor td ) {
246 readyInVars.add( td );
249 public Set<TempDescriptor> getReadyInVarSet() {
253 public void addStaticInVar( TempDescriptor td ) {
254 staticInVars.add( td );
257 public Set<TempDescriptor> getStaticInVarSet() {
261 public void putStaticInVar2src( TempDescriptor staticInVar,
262 VariableSourceToken vst ) {
263 staticInVar2src.put( staticInVar, vst );
266 public VariableSourceToken getStaticInVarSrc( TempDescriptor staticInVar ) {
267 return staticInVar2src.get( staticInVar );
270 public void addDynamicInVar( TempDescriptor td ) {
271 dynamicInVars.add( td );
274 public Set<TempDescriptor> getDynamicInVarSet() {
275 return dynamicInVars;
278 public void addDynamicVar( TempDescriptor td ) {
279 dynamicVars.add( td );
282 public Set<TempDescriptor> getDynamicVarSet() {
286 public void mustTrackAtLeastAge( Integer age ) {
287 if( age > oldestAgeToTrack ) {
288 oldestAgeToTrack = new Integer( age );
292 public Integer getOldestAgeToTrack() {
293 return oldestAgeToTrack;
296 public void setfmEnclosing( FlatMethod fm ) { fmEnclosing = fm; }
297 public FlatMethod getfmEnclosing() { return fmEnclosing; }
299 public void setmdEnclosing( MethodDescriptor md ) { mdEnclosing = md; }
300 public MethodDescriptor getmdEnclosing() { return mdEnclosing; }
302 public void setcdEnclosing( ClassDescriptor cd ) { cdEnclosing = cd; }
303 public ClassDescriptor getcdEnclosing() { return cdEnclosing; }
305 public void setfmBogus( FlatMethod fm ) { fmBogus = fm; }
306 public FlatMethod getfmBogus() { return fmBogus; }
308 public void setmdBogus( MethodDescriptor md ) { mdBogus = md; }
309 public MethodDescriptor getmdBogus() { return mdBogus; }
311 public String getSESEmethodName() {
312 assert cdEnclosing != null;
313 assert mdBogus != null;
316 cdEnclosing.getSafeSymbol()+
317 mdBogus.getSafeSymbol()+
319 mdBogus.getSafeMethodDescriptor();
322 public String getSESErecordName() {
323 assert cdEnclosing != null;
324 assert mdBogus != null;
328 cdEnclosing.getSafeSymbol()+
329 mdBogus.getSafeSymbol()+
331 mdBogus.getSafeMethodDescriptor()+
335 public void setCallerSESEplaceholder() {
336 isCallerSESEplaceholder = true;
339 public boolean getIsCallerSESEplaceholder() {
340 return isCallerSESEplaceholder;
344 public boolean equals( Object o ) {
349 if( !(o instanceof FlatSESEEnterNode) ) {
353 FlatSESEEnterNode fsen = (FlatSESEEnterNode) o;
354 return id == fsen.id;
357 public int hashCode() {
361 public void writeEffects(TempDescriptor td, String fd, TypeDescriptor type, HeapRegionNode hrn, boolean strongUpdate){
362 seseEffectsSet.addWritingVar(td, new SESEEffectsKey(fd, type, hrn.getID(), hrn.getGloballyUniqueIdentifier()));
364 seseEffectsSet.addStrongUpdateVar(td, new SESEEffectsKey(fd, type, hrn.getID(), hrn.getGloballyUniqueIdentifier()));
368 public void readEffects(TempDescriptor td, String fd, TypeDescriptor type, HeapRegionNode hrn ){
369 seseEffectsSet.addReadingVar(td, new SESEEffectsKey(fd, type, hrn.getID(), hrn.getGloballyUniqueIdentifier()));
372 public SESEEffectsSet getSeseEffectsSet(){
373 return seseEffectsSet;
377 public void setFirstDepRecField( String field ) {
378 firstDepRecField = field;
381 public String getFirstDepRecField() {
382 return firstDepRecField;
385 public void incNumDepRecs() {
389 public int getNumDepRecs() {
393 public Set<TempDescriptor> getInVarsForDynamicCoarseConflictResolution() {
394 return inVarsForDynamicCoarseConflictResolution;
397 public void addInVarForDynamicCoarseConflictResolution(TempDescriptor inVar) {
398 inVarsForDynamicCoarseConflictResolution.add(inVar);