return og.hasPotentialAlias( paramIndex, alloc );
}
- /*
public boolean createsPotentialAliases( Descriptor taskOrMethod,
AllocationSite alloc1,
AllocationSite alloc2 ) {
OwnershipGraph og = mapDescriptorToCompleteOwnershipGraph.get( taskOrMethod );
assert( og != null );
- return createsPotentialAliases( og,
- getHeapRegionIDset( alloc1 ),
- getHeapRegionIDset( alloc2 ) );
+ return og.hasPotentialAlias( alloc1, alloc2 );
}
-
- public boolean createsPotentialAliases( Descriptor taskOrMethod,
- AllocationSite alloc,
- HashSet<AllocationSite> allocSet ) {
- OwnershipGraph og = mapDescriptorToCompleteOwnershipGraph.get( taskOrMethod );
- assert( og != null );
- return createsPotentialAliases( og,
- getHeapRegionIDset( alloc ),
- getHeapRegionIDset( allocSet ) );
- }
- */
// use the methods given above to check every possible alias
// between task parameters and flagged allocation sites reachable
while( taskItr.hasNext() ) {
TaskDescriptor td = (TaskDescriptor) taskItr.next();
+ bw.write( "\n---------"+td+"--------\n" );
+
HashSet<AllocationSite> allocSites = getFlaggedAllocationSitesReachableFromTask( td );
// for each task parameter, check for aliases with
for( int j = i + 1; j < fm.numParameters(); ++j ) {
if( createsPotentialAliases( td, i, j ) ) {
foundSomeAlias = true;
- bw.write( "Task "+td+" potentially aliases parameters "+i+" and "+j+".\n" );
+ bw.write( "Potential alias between parameters "+i+" and "+j+".\n" );
}
}
AllocationSite as = (AllocationSite) allocItr.next();
if( createsPotentialAliases( td, i, as ) ) {
foundSomeAlias = true;
- bw.write( "Task "+td+" potentially aliases parameter "+i+" and "+as+".\n" );
+ bw.write( "Potential alias between parameter "+i+" and "+as+".\n" );
}
}
}
- /*
// for each allocation site check for aliases with
// other allocation sites in the context of execution
// of this task
- Iterator allocItr = allocSites.iterator();
- while( allocItr.hasNext() ) {
- AllocationSite as = (AllocationSite) allocItr.next();
- if( createsPotentialAliases( td, as, allocSites ) ) {
- bw.write( "Task "+td+" potentially aliases "+as+" and the rest of the set.\n" );
+ HashSet<AllocationSite> outerChecked = new HashSet<AllocationSite>();
+ Iterator allocItr1 = allocSites.iterator();
+ while( allocItr1.hasNext() ) {
+ AllocationSite as1 = (AllocationSite) allocItr1.next();
+
+ Iterator allocItr2 = allocSites.iterator();
+ while( allocItr2.hasNext() ) {
+ AllocationSite as2 = (AllocationSite) allocItr2.next();
+
+ if( !outerChecked.contains( as2 ) &&
+ createsPotentialAliases( td, as1, as2 ) ) {
+ bw.write( "Potential alias between "+as1+" and "+as2+".\n" );
+ }
}
+
+ outerChecked.add( as1 );
}
- */
if( !foundSomeAlias ) {
bw.write( "Task "+td+" contains no aliases between flagged objects.\n" );
return asSetTotal;
}
-
-
-
- private HashSet<Integer> getHeapRegionIDset(OwnershipGraph og,
- int paramIndex) {
-
- assert og.paramIndex2id.containsKey(paramIndex);
- Integer idParam = og.paramIndex2id.get(paramIndex);
-
- HashSet<Integer> idSet = new HashSet<Integer>();
- idSet.add(idParam);
-
- return idSet;
- }
-
-
- private HashSet<Integer> getHeapRegionIDset(AllocationSite alloc) {
-
- HashSet<Integer> idSet = new HashSet<Integer>();
-
- for( int i = 0; i < alloc.getAllocationDepth(); ++i ) {
- Integer id = alloc.getIthOldest(i);
- idSet.add(id);
- }
-
- Integer idSummary = alloc.getSummary();
- idSet.add(idSummary);
-
- return idSet;
- }
-
- private HashSet<Integer> getHeapRegionIDset(HashSet<AllocationSite> allocSet) {
-
- HashSet<Integer> idSet = new HashSet<Integer>();
-
- Iterator allocItr = allocSet.iterator();
- while( allocItr.hasNext() ) {
- AllocationSite alloc = (AllocationSite) allocItr.next();
-
- for( int i = 0; i < alloc.getAllocationDepth(); ++i ) {
- Integer id = alloc.getIthOldest(i);
- idSet.add(id);
- }
-
- Integer idSummary = alloc.getSummary();
- idSet.add(idSummary);
- }
-
- return idSet;
- }
-
- private boolean createsPotentialAliases(OwnershipGraph og,
- HashSet<Integer> idSetA,
- HashSet<Integer> idSetB) {
- boolean potentialAlias = false;
-
- /*
- // first expand set B into the set of all heap region node ID's
- // reachable from the nodes in set B
- HashSet<Integer> idSetReachableFromB = og.getReachableSet( idSetB );
-
- // then see if anything in A can reach a node in the set reachable
- // from B. If so, there is a potential alias.
- Iterator i = idSetA.iterator();
- while( i.hasNext() ) {
- Integer id = (Integer) i.next();
- if( og.canIdReachSet( id, idSetB ) ) {
- return true;
- }
- }
- */
-
- return false;
- }
}
}
- /*
- // given a set B of heap region node ID's, return the set of heap
- // region node ID's that is reachable from B
- public HashSet<Integer> getReachableSet( HashSet<Integer> idSetB ) {
-
- HashSet<HeapRegionNode> toVisit = new HashSet<HeapRegionNode>();
- HashSet<HeapRegionNode> visited = new HashSet<HeapRegionNode>();
-
- // initial nodes to visit are from set B
- Iterator initialItr = idSetB.iterator();
- while( initialItr.hasNext() ) {
- Integer idInitial = (Integer) initialItr.next();
- assert id2hrn.contains( idInitial );
- HeapRegionNode hrnInitial = id2hrn.get( idInitial );
- toVisit.add( hrnInitial );
- }
-
- HashSet<Integer> idSetReachableFromB = new HashSet<Integer>();
-
- // do a heap traversal
- while( !toVisit.isEmpty() ) {
- HeapRegionNode hrnVisited = (HeapRegionNode) toVisit.iterator().next();
- toVisit.remove( hrnVisited );
- visited.add ( hrnVisited );
-
- // for every node visited, add it to the total
- // reachable set
- idSetReachableFromB.add( hrnVisited.getID() );
-
- // find other reachable nodes
- Iterator referenceeItr = hrnVisited.setIteratorToReferencedRegions();
- while( referenceeItr.hasNext() ) {
- Map.Entry me = (Map.Entry) referenceeItr.next();
- HeapRegionNode hrnReferencee = (HeapRegionNode) me.getKey();
- ReferenceEdgeProperties rep = (ReferenceEdgeProperties) me.getValue();
-
- if( !visited.contains( hrnReferencee ) ) {
- toVisit.add( hrnReferencee );
- }
- }
- }
-
- return idSetReachableFromB;
- }
-
-
- // used to find if a heap region can possibly have a reference to
- // any of the heap regions in the given set
- // if the id supplied is in the set, then a self-referencing edge
- // would return true, but that special case is specifically allowed
- // meaning that it isn't an external alias
- public boolean canIdReachSet( Integer id, HashSet<Integer> idSet ) {
-
- assert id2hrn.contains( id );
- HeapRegionNode hrn = id2hrn.get( id );
-
-
- //HashSet<HeapRegionNode> hrnSet = new HashSet<HeapRegionNode>();
-
- //Iterator i = idSet.iterator();
- //while( i.hasNext() ) {
- // Integer idFromSet = (Integer) i.next();
- // assert id2hrn.contains( idFromSet );
- // hrnSet.add( id2hrn.get( idFromSet ) );
- //}
-
-
- // do a traversal from hrn and see if any of the
- // heap regions from the set come up during that
- HashSet<HeapRegionNode> toVisit = new HashSet<HeapRegionNode>();
- HashSet<HeapRegionNode> visited = new HashSet<HeapRegionNode>();
-
- toVisit.add( hrn );
- while( !toVisit.isEmpty() ) {
- HeapRegionNode hrnVisited = (HeapRegionNode) toVisit.iterator().next();
- toVisit.remove( hrnVisited );
- visited.add ( hrnVisited );
+ public boolean hasPotentialAlias( AllocationSite as1, AllocationSite as2 ) {
- Iterator referenceeItr = hrnVisited.setIteratorToReferencedRegions();
- while( referenceeItr.hasNext() ) {
- Map.Entry me = (Map.Entry) referenceeItr.next();
- HeapRegionNode hrnReferencee = (HeapRegionNode) me.getKey();
- ReferenceEdgeProperties rep = (ReferenceEdgeProperties) me.getValue();
+ // get tokens for summary nodes
+ TokenTuple gs1 = new TokenTuple(as1.getSummary(),
+ true,
+ TokenTuple.ARITY_ONE).makeCanonical();
+
+ TokenTuple gsStar1 = new TokenTuple(as1.getSummary(),
+ true,
+ TokenTuple.ARITY_MANY).makeCanonical();
+
+ // get summary node's alpha
+ Integer idSum1 = as1.getSummary();
+ assert id2hrn.containsKey( idSum1 );
+ HeapRegionNode hrnSum1 = id2hrn.get( idSum1 );
+ assert hrnSum1 != null;
+ ReachabilitySet alphaSum1 = hrnSum1.getAlpha();
+ assert alphaSum1 != null;
+
+
+ // and for the other one
+ TokenTuple gs2 = new TokenTuple(as2.getSummary(),
+ true,
+ TokenTuple.ARITY_ONE).makeCanonical();
+
+ TokenTuple gsStar2 = new TokenTuple(as2.getSummary(),
+ true,
+ TokenTuple.ARITY_MANY).makeCanonical();
+
+ // get summary node's alpha
+ Integer idSum2 = as2.getSummary();
+ assert id2hrn.containsKey( idSum2 );
+ HeapRegionNode hrnSum2 = id2hrn.get( idSum2 );
+ assert hrnSum2 != null;
+ ReachabilitySet alphaSum2 = hrnSum2.getAlpha();
+ assert alphaSum2 != null;
+
+ // does either one report reachability from the other tokens?
+ if( alphaSum1.containsTuple( gsStar2 ) ) { return true; }
+ if( alphaSum2.containsTuple( gsStar1 ) ) { return true; }
+
+ // only check non-star token if they are different sites
+ if( as1 != as2 ) {
+ if( alphaSum1.containsTuple( gs2 ) ) { return true; }
+ if( alphaSum2.containsTuple( gs1 ) ) { return true; }
+ }
+
+
+ // check sum2 against alloc1 nodes
+ for( int i = 0; i < as1.getAllocationDepth(); ++i ) {
+ Integer idI1 = as1.getIthOldest(i);
+ assert id2hrn.containsKey( idI1 );
+ HeapRegionNode hrnI1 = id2hrn.get( idI1 );
+ assert hrnI1 != null;
+ ReachabilitySet alphaI1 = hrnI1.getAlpha();
+ assert alphaI1 != null;
- if( idSet.contains( hrnReferencee.getID() ) ) {
- if( !id.equals( hrnReferencee.getID() ) ) {
- return true;
- }
- }
+ // the other nodes of an allocation site are single, no stars
+ TokenTuple gi1 = new TokenTuple(as1.getIthOldest(i),
+ false,
+ TokenTuple.ARITY_ONE).makeCanonical();
- if( !visited.contains( hrnReferencee ) ) {
- toVisit.add( hrnReferencee );
- }
- }
- }
+ if( alphaSum2.containsTuple( gi1 ) ) { return true; }
+ if( alphaI1.containsTuple ( gs2 ) ) { return true; }
+ if( alphaI1.containsTuple ( gsStar2 ) ) { return true; }
+ }
- return false;
- }
- */
+ // check sum1 against alloc2 nodes
+ for( int i = 0; i < as2.getAllocationDepth(); ++i ) {
+ Integer idI2 = as2.getIthOldest(i);
+ assert id2hrn.containsKey( idI2 );
+ HeapRegionNode hrnI2 = id2hrn.get( idI2 );
+ assert hrnI2 != null;
+ ReachabilitySet alphaI2 = hrnI2.getAlpha();
+ assert alphaI2 != null;
+
+ TokenTuple gi2 = new TokenTuple(as2.getIthOldest(i),
+ false,
+ TokenTuple.ARITY_ONE).makeCanonical();
+
+ if( alphaSum1.containsTuple( gi2 ) ) { return true; }
+ if( alphaI2.containsTuple ( gs1 ) ) { return true; }
+ if( alphaI2.containsTuple ( gsStar1 ) ) { return true; }
+
+ // while we're at it, do an inner loop for alloc2 vs alloc1 nodes
+ for( int j = 0; j < as1.getAllocationDepth(); ++j ) {
+ Integer idI1 = as1.getIthOldest(j);
+
+ // if these are the same site, don't look for the same token, no alias
+ // different tokens of the same site could alias together though
+ if( idI1 == idI2 ) { continue; }
+
+ HeapRegionNode hrnI1 = id2hrn.get( idI1 );
+ ReachabilitySet alphaI1 = hrnI1.getAlpha();
+ TokenTuple gi1 = new TokenTuple(as1.getIthOldest(j),
+ false,
+ TokenTuple.ARITY_ONE).makeCanonical();
+ if( alphaI2.containsTuple( gi1 ) ) { return true; }
+ if( alphaI1.containsTuple( gi2 ) ) { return true; }
+ }
+ }
+
+ return false;
+ }
// for writing ownership graphs to dot files