Working on allocating with reachability, mostly the "aging" of tokens.
authorjjenista <jjenista>
Fri, 18 Jul 2008 19:29:25 +0000 (19:29 +0000)
committerjjenista <jjenista>
Fri, 18 Jul 2008 19:29:25 +0000 (19:29 +0000)
Implementation is stable but it is not working correctly.

Robust/src/Analysis/OwnershipAnalysis/AllocationSite.java
Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java
Robust/src/Analysis/OwnershipAnalysis/ReachabilitySet.java
Robust/src/Analysis/OwnershipAnalysis/TokenTuple.java
Robust/src/Analysis/OwnershipAnalysis/TokenTupleSet.java

index d6ffc614c551280e714192904fe8b15a5e3b9102..fb02f4611ea60558eb80165b4d4f00f340b1394a 100644 (file)
@@ -29,6 +29,10 @@ public class AllocationSite {
     protected Integer         summary;
     protected TypeDescriptor  type;
 
+    public static final int AGE_notInThisSite = -1;
+    public static final int AGE_oldest        = -2;
+    public static final int AGE_summary       = -3;
+
 
     public AllocationSite( int allocationDepth, TypeDescriptor type ) {
        assert allocationDepth >= 3;
@@ -82,6 +86,24 @@ public class AllocationSite {
        return type;
     }
 
+    public int getAge( Integer id ) {
+       if( id.equals( summary ) ) {
+           return AGE_summary;
+       }
+       
+       if( id.equals( getOldest() ) ) {
+           return AGE_oldest;
+       }
+
+       for( int i = 0; i < allocationDepth - 1; ++i ) {
+           if( id.equals( ithOldest.get( i ) ) ) {
+               return i;
+           }
+       }
+
+       return AGE_notInThisSite;   
+    }
+
     public String toString() {
        return "allocSite" + id;
     }
index ef55faed9564a09611306d3755dd834ba7b7963c..ab25e11a0ea8a44505975deb763f10a2c6b9a4e6 100644 (file)
@@ -579,6 +579,7 @@ public class OwnershipGraph {
            ReferenceEdgeProperties rep = (ReferenceEdgeProperties) me.getValue();
            
            // determine if another summary node is already referencing this referencee
+           /*
            boolean       hasSummaryReferencer = false;
            OwnershipNode onReferencer         = null;
            Iterator      itrReferencer        = hrnReferencee.iteratorToReferencers();
@@ -595,6 +596,20 @@ public class OwnershipGraph {
            addReferenceEdge( hrnSummary,
                              hrnReferencee,
                              new ReferenceEdgeProperties( !hasSummaryReferencer ) );
+           */
+
+           ReferenceEdgeProperties repSummary = hrnSummary.getReferenceTo( hrnReferencee );
+           ReferenceEdgeProperties repMerged = rep.copy();
+
+           if( repSummary == null ) {      
+               // the merge is trivial, nothing to be done
+           } else {
+               // otherwise an edge from the referencer to alpha_S exists already
+               // and the edge referencer->alpha_K should be merged with it
+               repMerged.setBeta( repMerged.getBeta().union( repSummary.getBeta() ) );
+           }
+
+           addReferenceEdge( hrnSummary, hrnReferencee, repMerged );
        }
 
        // next transfer references to alpha_k over to alpha_s
@@ -675,6 +690,47 @@ public class OwnershipGraph {
        // clear all references in and out of newest node
        clearReferenceEdgesFrom( hrn0 );
        clearReferenceEdgesTo  ( hrn0 );
+
+       // now tokens in reachability sets need to "age" as well
+       ReferenceEdgeProperties repToAge = null;
+       Iterator itrAllLabelNodes = td2ln.entrySet().iterator();
+       while( itrAllLabelNodes.hasNext() ) {
+           Map.Entry me = (Map.Entry) itrAllLabelNodes.next();
+           LabelNode ln = (LabelNode) me.getValue();
+
+           Iterator itrEdges = ln.setIteratorToReferencedRegions();
+           while( itrEdges.hasNext() ) {
+               Map.Entry meE = (Map.Entry)               itrEdges.next();
+               repToAge      = (ReferenceEdgeProperties) meE.getValue();
+
+               ageTokens( as, repToAge );
+           }
+       }
+
+       HeapRegionNode hrnToAge = null;
+       Iterator itrAllHRNodes = id2hrn.entrySet().iterator();
+       while( itrAllHRNodes.hasNext() ) {
+           Map.Entry me = (Map.Entry)               itrAllHRNodes.next();
+           hrnToAge     = (HeapRegionNode)          me.getValue();
+
+           ageTokens( as, hrnToAge );
+
+           Iterator itrEdges = hrnToAge.setIteratorToReferencedRegions();
+           while( itrEdges.hasNext() ) {
+               Map.Entry meE = (Map.Entry)               itrEdges.next();
+               repToAge      = (ReferenceEdgeProperties) meE.getValue();
+
+               ageTokens( as, repToAge );
+           }
+       }               
+    }
+
+    protected void ageTokens( AllocationSite as, ReferenceEdgeProperties rep ) {
+       rep.setBeta( rep.getBeta().ageTokens( as ) );
+    }
+
+    protected void ageTokens( AllocationSite as, HeapRegionNode hrn ) {
+       hrn.setAlpha( hrn.getAlpha().ageTokens( as ) );
     }
 
     
index e794074113104c042bb103b579d2fae6e1c39dc6..b3a35fcfb1d3641c45bcccf5d7aeddb92351c726 100644 (file)
@@ -201,6 +201,19 @@ public class ReachabilitySet extends Canonical {
     }
 
 
+    public ReachabilitySet ageTokens( AllocationSite as ) {
+       ReachabilitySet rsOut = new ReachabilitySet();
+
+       Iterator itrS = this.iterator();
+       while( itrS.hasNext() ) {
+           TokenTupleSet tts = (TokenTupleSet) itrS.next();
+           rsOut.possibleReachabilities.add( tts.ageTokens( as ) );
+       }
+
+       return rsOut.makeCanonical();
+    }
+
+
     public boolean equals( Object o ) {
        if( !(o instanceof ReachabilitySet) ) {
            return false;
@@ -235,17 +248,13 @@ public class ReachabilitySet extends Canonical {
 
        Iterator i = this.iterator();
        while( i.hasNext() ) {
-           if( possibleReachabilities.size() > 1 ) {
+           s += i.next();
+           if( i.hasNext() ) {
                s += "\n";
            }
-           s += " "+i.next();
-       }
-       
-       if( possibleReachabilities.size() > 1 ) {
-           s += "\n";
        }
 
-       s += " ]";
+       s += "]";
        return s;       
     }
 }
index cd2f248b597e531c6c96f5a498a1ca612539431a..acaf257dc7e674811ed2eb86c3e6c56e505170c5 100644 (file)
@@ -51,6 +51,14 @@ public class TokenTuple extends Canonical
        return this;
     }
 
+    public TokenTuple changeTokenTo( Integer tokenToChangeTo ) {
+       assert isNewSummary == false;
+
+       return new TokenTuple( tokenToChangeTo,
+                              isNewSummary,
+                              arity ).makeCanonical();
+    }
+
     public boolean equals( Object o ) {
        if( !(o instanceof TokenTuple) ) {
            return false;
index d08c00732cac7940a226d8abdf26822143790e04..ecf0633eb39d89639a6a3e852082ef871e020c99 100644 (file)
@@ -143,6 +143,66 @@ public class TokenTupleSet extends Canonical {
        return false;
     }
 
+    public TokenTupleSet ageTokens( AllocationSite as ) {
+       TokenTupleSet ttsOut = new TokenTupleSet( this );
+
+       TokenTuple ttSummary = null;
+       boolean foundOldest  = false;
+
+       Iterator itrT = this.iterator();
+       while( itrT.hasNext() ) {
+           TokenTuple tt = (TokenTuple) itrT.next();
+
+           Integer token = tt.getToken();
+           int age = as.getAge( token );
+
+           // summary tokens and tokens not associated with
+           // the site should be left alone
+           if( age != AllocationSite.AGE_notInThisSite ) {
+
+               if( age == AllocationSite.AGE_summary ) {
+                   // remember the summary tuple, but don't add it
+                   // we may combine it with the oldest tuple
+                   ttSummary = tt;
+
+               } else if( age == AllocationSite.AGE_oldest ) {
+                   // found a token                
+                   foundOldest = true;
+
+               } else {
+                   // otherwise, we change this token to the
+                   // next older token
+                   Integer tokenToChangeTo = as.getIthOldest( age + 1 );
+                   tt = tt.changeTokenTo( tokenToChangeTo );
+               }
+           }
+
+           ttsOut.add( tt );
+       }
+
+       // there are four cases to consider here
+       // 1. we found a summary tuple and no oldest tuple
+       //    Here we just pass the summary unchanged
+       // 2. we found an oldest tuple, no summary
+       //    Make a new, arity-one summary tuple
+       // 3. we found both a summary and an oldest
+       //    Merge them by increasing arity of summary
+       // 4. (not handled) we found neither, do nothing
+       if       ( ttSummary != null && !foundOldest ) {
+           ttsOut.add( ttSummary );
+
+       } else if( ttSummary == null &&  foundOldest ) {
+           ttsOut.add( new TokenTuple( as.getSummary(),
+                                       true,
+                                       TokenTuple.ARITY_ONE ).makeCanonical() );          
+       
+       } else if( ttSummary != null &&  foundOldest ) {
+           ttsOut.add( ttSummary.increaseArity() );
+       }
+
+       return ttsOut.makeCanonical();
+    }
+
     public String toString() {
        return tokenTuples.toString();
     }