From e3ec14e226adad043ddcd9a648241a61cc6d1adb Mon Sep 17 00:00:00 2001 From: jjenista Date: Thu, 7 Aug 2008 18:37:09 +0000 Subject: [PATCH] Bug fix that param2id tables need to initialized for every method before starting analysis --- .../OwnershipAnalysis/OwnershipAnalysis.java | 40 ++++++------ .../OwnershipAnalysis/OwnershipGraph.java | 65 +++++++++++++++++-- .../OwnershipAnalysis/ReachabilitySet.java | 2 - 3 files changed, 82 insertions(+), 25 deletions(-) diff --git a/Robust/src/Analysis/OwnershipAnalysis/OwnershipAnalysis.java b/Robust/src/Analysis/OwnershipAnalysis/OwnershipAnalysis.java index 016929e8..8e04335b 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/OwnershipAnalysis.java +++ b/Robust/src/Analysis/OwnershipAnalysis/OwnershipAnalysis.java @@ -206,6 +206,7 @@ public class OwnershipAnalysis { // traversing the call graph HashSet calleesScheduled = new HashSet(); + // initialize methods to visit as the set of all tasks in the // program and then any method that could be called starting // from those tasks @@ -218,6 +219,26 @@ public class OwnershipAnalysis { scheduleAllCallees( calleesScheduled, d ); } + // before beginning analysis, initialize every scheduled method + // with an ownership graph that has populated parameter index tables + // by analyzing the first node which is always a FlatMethod node + Iterator dItr = calleesScheduled.iterator(); + while( dItr.hasNext() ) { + Descriptor d = dItr.next(); + OwnershipGraph og = new OwnershipGraph( allocationDepth ); + + FlatMethod fm; + if( d instanceof MethodDescriptor ) { + fm = state.getMethodFlat( (MethodDescriptor) d ); + } else { + assert d instanceof TaskDescriptor; + fm = state.getMethodFlat( (TaskDescriptor) d ); + } + + analyzeFlatNode( d, fm, null, og ); + mapDescriptorToCompleteOwnershipGraph.put( d, og ); + } + // as mentioned above, analyze methods one-by-one, possibly revisiting // a method if the methods that it calls are updated analyzeMethods(); @@ -317,11 +338,6 @@ public class OwnershipAnalysis { // the final ownership graph result to return as an empty set returnNodesToCombineForCompleteOwnershipGraph = new HashSet(); - - // DEBUG - //int x = 0; - - while( !flatNodesToVisit.isEmpty() ) { FlatNode fn = (FlatNode) flatNodesToVisit.iterator().next(); flatNodesToVisit.remove( fn ); @@ -355,20 +371,6 @@ public class OwnershipAnalysis { if( !og.equals( ogPrev ) ) { setGraphForFlatNode( fn, og ); - // DEBUG - /* - ++x; - - if( x > 5000 ) { - String s = String.format( "%04d", x ); - og.writeGraph( "debug"+s, false, false ); - } - - if( x == 5020 ) { - System.exit( -1 ); - } - */ - for( int i = 0; i < fn.numNext(); i++ ) { FlatNode nn = fn.getNext( i ); flatNodesToVisit.add( nn ); diff --git a/Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java b/Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java index bd5d6ef9..a955920e 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java +++ b/Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java @@ -823,9 +823,9 @@ public class OwnershipGraph { // verify the existence of allocation sites and their // shadows from the callee in the context of this caller graph - Iterator i = ogCallee.allocationSites.iterator(); - while( i.hasNext() ) { - AllocationSite allocSite = i.next(); + Iterator asItr = ogCallee.allocationSites.iterator(); + while( asItr.hasNext() ) { + AllocationSite allocSite = asItr.next(); HeapRegionNode hrnSummary = getSummaryNode ( allocSite ); HeapRegionNode hrnShadowSummary = getShadowSummaryNode( allocSite ); } @@ -838,6 +838,63 @@ public class OwnershipGraph { assert fc.numArgs() + 1 == fm.numParameters(); } + // make a change set to translate callee tokens into caller tokens + ChangeTupleSet C = new ChangeTupleSet().makeCanonical(); + + for( int i = 0; i < fm.numParameters(); ++i ) { + + Integer indexParam = new Integer( i ); + + System.out.println( "In method "+fm+ " on param "+indexParam ); + + assert ogCallee.paramIndex2id.containsKey( indexParam ); + Integer idParam = ogCallee.paramIndex2id.get( indexParam ); + + assert ogCallee.id2hrn.containsKey( idParam ); + HeapRegionNode hrnParam = ogCallee.id2hrn.get( idParam ); + assert hrnParam != null; + + TokenTupleSet calleeTokenToMatch = + new TokenTupleSet( new TokenTuple( hrnParam ) ).makeCanonical(); + + + // now depending on whether the callee is static or not + // we need to account for a "this" argument in order to + // find the matching argument in the caller context + TempDescriptor argTemp; + if( isStatic ) { + argTemp = fc.getArg( indexParam ); + } else { + if( indexParam == 0 ) { + argTemp = fc.getThis(); + } else { + argTemp = fc.getArg( indexParam - 1 ); + } + } + + LabelNode argLabel = getLabelNodeFromTemp( argTemp ); + Iterator argHeapRegionsItr = argLabel.setIteratorToReferencedRegions(); + while( argHeapRegionsItr.hasNext() ) { + Map.Entry meArg = (Map.Entry) argHeapRegionsItr.next(); + HeapRegionNode argHeapRegion = (HeapRegionNode) meArg.getKey(); + ReferenceEdgeProperties repArg = (ReferenceEdgeProperties) meArg.getValue(); + + Iterator ttsItr = repArg.getBeta().iterator(); + while( ttsItr.hasNext() ) { + TokenTupleSet callerTokensToReplace = ttsItr.next(); + + ChangeTuple ct = new ChangeTuple( calleeTokenToMatch, + callerTokensToReplace ).makeCanonical(); + + C = C.union( ct ); + } + } + } + + System.out.println( "Applying method call "+fm ); + System.out.println( " Change: "+C ); + + // the heap regions represented by the arguments (caller graph) // and heap regions for the parameters (callee graph) // don't correspond to each other by heap region ID. In fact, @@ -992,7 +1049,7 @@ public class OwnershipGraph { mergeOwnershipNodes ( og ); mergeReferenceEdges ( og ); - mergeId2paramIndex ( og ); + mergeId2paramIndex ( og ); mergeAllocationSites( og ); } diff --git a/Robust/src/Analysis/OwnershipAnalysis/ReachabilitySet.java b/Robust/src/Analysis/OwnershipAnalysis/ReachabilitySet.java index 08b2b7a8..3adead10 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/ReachabilitySet.java +++ b/Robust/src/Analysis/OwnershipAnalysis/ReachabilitySet.java @@ -12,8 +12,6 @@ public class ReachabilitySet extends Canonical { public ReachabilitySet() { possibleReachabilities = new HashSet(); - //TokenTupleSet ttsEmpty = new TokenTupleSet().makeCanonical(); - //possibleReachabilities.add( ttsEmpty ); } public ReachabilitySet( TokenTupleSet tts ) { -- 2.34.1