From: jjenista Date: Wed, 27 Aug 2008 19:07:20 +0000 (+0000) Subject: write-to-graph changes X-Git-Tag: buildscript^6~77 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=cbf151591779787253ac2d6fb03ed8ad0ea838be;p=IRC.git write-to-graph changes --- diff --git a/Robust/src/Analysis/CallGraph/CallGraph.java b/Robust/src/Analysis/CallGraph/CallGraph.java index 393a86be..1c24b244 100644 --- a/Robust/src/Analysis/CallGraph/CallGraph.java +++ b/Robust/src/Analysis/CallGraph/CallGraph.java @@ -101,17 +101,17 @@ public class CallGraph { /** Given a call to MethodDescriptor, lists the methods which could actually be call by that method. */ public Set getMethodCalls(TaskDescriptor td) { - return getMethodCalls( (Descriptor) td ); + return getMethodCalls( (Descriptor) td); } public Set getMethodCalls(MethodDescriptor md) { - return getMethodCalls( (Descriptor) md ); + return getMethodCalls( (Descriptor) md); } public Set getMethodCalls(Descriptor d) { assert d instanceof MethodDescriptor || - d instanceof TaskDescriptor; - + d instanceof TaskDescriptor; + HashSet ns=new HashSet(); ns.add(d); Set s=(Set)mapCaller2CalleeSet.get(d); @@ -188,9 +188,9 @@ public class CallGraph { bw.write("digraph "+graphName+" {\n"); Iterator mapItr = mapVirtual2ImplementationSet.entrySet().iterator(); while( mapItr.hasNext() ) { - Map.Entry me = (Map.Entry) mapItr.next(); + Map.Entry me = (Map.Entry)mapItr.next(); MethodDescriptor virtual = (MethodDescriptor) me.getKey(); - HashSet implemSet = (HashSet) me.getValue(); + HashSet implemSet = (HashSet) me.getValue(); if( !labeledInDot.contains(virtual) ) { labeledInDot.add(virtual); @@ -222,35 +222,25 @@ public class CallGraph { bw.write("digraph "+graphName+"byCallers {\n"); Iterator mapItr = mapCaller2CalleeSet.entrySet().iterator(); while( mapItr.hasNext() ) { - Map.Entry me = (Map.Entry)mapItr.next(); - Descriptor caller = (Descriptor) me.getKey(); + Map.Entry me = (Map.Entry)mapItr.next(); + Descriptor caller = (Descriptor) me.getKey(); HashSet calleeSet = (HashSet) me.getValue(); - String callerString = caller.toString().replaceAll("[\\W]", ""); - - /* if( !labeledInDot.contains(caller) ) { labeledInDot.add(caller); - bw.write(" " + caller.getNum() + "[label=\"" + callerString + "\"];\n"); + bw.write(" "+caller.getNum()+"[label=\"" +caller+"\"];\n"); } - */ Iterator calleeItr = calleeSet.iterator(); while( calleeItr.hasNext() ) { MethodDescriptor callee = (MethodDescriptor) calleeItr.next(); - String calleeString = callee.toString().replaceAll("[\\W]", ""); - - /* if( !labeledInDot.contains(callee) ) { labeledInDot.add(callee); - bw.write(" " + callee.getNum() + "[label=\"" + calleeString + "\"];\n"); + bw.write(" "+callee.getNum()+"[label=\""+callee+"\"];\n"); } - */ - bw.write(" " + caller.getNum() + "->" + callee.getNum() + ";\n"); - - //bw.write(" " + callerString + "->" + calleeString + ";\n"); + bw.write(" "+caller.getNum()+"->"+callee.getNum()+";\n"); } } bw.write("}\n"); @@ -272,31 +262,21 @@ public class CallGraph { MethodDescriptor callee = (MethodDescriptor) me.getKey(); HashSet callerSet = (HashSet) me.getValue(); - String calleeString = callee.toString().replaceAll("[\\W]", ""); - - /* if( !labeledInDot.contains(callee) ) { labeledInDot.add(callee); - bw.write(" " + callee.getNum() + "[label=\"" + calleeString + "\"];\n"); + bw.write(" "+callee.getNum()+"[label=\""+callee+"\"];\n"); } - */ Iterator callerItr = callerSet.iterator(); while( callerItr.hasNext() ) { Descriptor caller = (Descriptor) callerItr.next(); - String callerString = caller.toString().replaceAll("[\\W]", ""); - /* if( !labeledInDot.contains(caller) ) { labeledInDot.add(caller); - bw.write(" " + caller.getNum() + "[label=\"" + callerString + "\"];\n"); + bw.write(" "+caller.getNum()+"[label=\""+caller+"\"];\n"); } - */ - - bw.write(" " + caller.getNum() + "->" + callee.getNum() + ";\n"); - - //bw.write(" " + callerString + "->" + calleeString + ";\n"); + bw.write(" "+caller.getNum()+"->"+callee.getNum()+";\n"); } } bw.write("}\n"); diff --git a/Robust/src/Analysis/OwnershipAnalysis/AllocationSite.java b/Robust/src/Analysis/OwnershipAnalysis/AllocationSite.java index 949dd465..3bcbdb7a 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/AllocationSite.java +++ b/Robust/src/Analysis/OwnershipAnalysis/AllocationSite.java @@ -108,7 +108,7 @@ public class AllocationSite { } public int getAgeCategory(Integer id) { - + if( id.equals(summary) ) { return AGE_summary; } @@ -129,13 +129,13 @@ public class AllocationSite { public Integer getAge(Integer id) { for( int i = 0; i < allocationDepth - 1; ++i ) { if( id.equals(ithOldest.get(i) ) ) { - return new Integer( i ); + return new Integer(i); } } - + return null; } - + public int getShadowAgeCategory(Integer id) { if( id.equals(-summary) ) { return SHADOWAGE_summary; @@ -146,7 +146,7 @@ public class AllocationSite { } for( int i = 0; i < allocationDepth - 1; ++i ) { - if( id.equals( getIthOldestShadow(i) ) ) { + if( id.equals(getIthOldestShadow(i) ) ) { return SHADOWAGE_in_I; } } @@ -154,10 +154,10 @@ public class AllocationSite { return SHADOWAGE_notInThisSite; } - public Integer getShadowAge( Integer id ) { + public Integer getShadowAge(Integer id) { for( int i = 0; i < allocationDepth - 1; ++i ) { - if( id.equals( getIthOldestShadow(i) ) ) { - return new Integer( -i ); + if( id.equals(getIthOldestShadow(i) ) ) { + return new Integer(-i); } } diff --git a/Robust/src/Analysis/OwnershipAnalysis/OwnershipAnalysis.java b/Robust/src/Analysis/OwnershipAnalysis/OwnershipAnalysis.java index 1c246e2a..ec254ec8 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/OwnershipAnalysis.java +++ b/Robust/src/Analysis/OwnershipAnalysis/OwnershipAnalysis.java @@ -245,10 +245,14 @@ public class OwnershipAnalysis { fm = state.getMethodFlat( (TaskDescriptor) d); } + System.out.println("Previsiting " + d); + analyzeFlatNode(d, fm, null, og); mapDescriptorToCompleteOwnershipGraph.put(d, og); } + System.out.println(""); + // as mentioned above, analyze methods one-by-one, possibly revisiting // a method if the methods that it calls are updated analyzeMethods(); @@ -263,12 +267,12 @@ public class OwnershipAnalysis { descriptorsToAnalyze.add(d); // start with all method calls to further schedule - Set moreMethodsToCheck = moreMethodsToCheck = callGraph.getMethodCalls( d ); + Set moreMethodsToCheck = moreMethodsToCheck = callGraph.getMethodCalls(d); if( d instanceof MethodDescriptor ) { // see if this method has virtual dispatch - Set virtualMethods = callGraph.getMethods( (MethodDescriptor)d ); - moreMethodsToCheck.addAll( virtualMethods ); + Set virtualMethods = callGraph.getMethods( (MethodDescriptor)d); + moreMethodsToCheck.addAll(virtualMethods); } // keep following any further methods identified in @@ -285,7 +289,7 @@ public class OwnershipAnalysis { // and be sure to reschedule tasks/methods when the methods // they call are updated private void analyzeMethods() throws java.io.IOException { - + descriptorsToVisit = (HashSet)descriptorsToAnalyze.clone(); while( !descriptorsToVisit.isEmpty() ) { @@ -310,18 +314,16 @@ public class OwnershipAnalysis { fm = state.getMethodFlat( (TaskDescriptor) d); } - OwnershipGraph og = analyzeFlatMethod(d, fm); + OwnershipGraph og = analyzeFlatMethod(d, fm); OwnershipGraph ogPrev = mapDescriptorToCompleteOwnershipGraph.get(d); if( !og.equals(ogPrev) ) { mapDescriptorToCompleteOwnershipGraph.put(d, og); - /* - boolean writeLabels, + /* boolean writeLabels, boolean labelSelect, boolean pruneGarbage, - boolean writeReferencers - */ - og.writeGraph(d, true, true, false, false); + boolean writeReferencers */ + og.writeGraph(d, true, true, true, false); // only methods have dependents, tasks cannot // be invoked by any user program calls @@ -332,7 +334,7 @@ public class OwnershipAnalysis { Iterator depItr = dependents.iterator(); while( depItr.hasNext() ) { Descriptor dependent = (Descriptor) depItr.next(); - if( descriptorsToAnalyze.contains( dependent ) ) { + if( descriptorsToAnalyze.contains(dependent) ) { descriptorsToVisit.add(dependent); } } @@ -364,6 +366,7 @@ public class OwnershipAnalysis { // the final ownership graph result to return as an empty set returnNodesToCombineForCompleteOwnershipGraph = new HashSet(); + while( !flatNodesToVisit.isEmpty() ) { FlatNode fn = (FlatNode) flatNodesToVisit.iterator().next(); flatNodesToVisit.remove(fn); @@ -424,8 +427,8 @@ public class OwnershipAnalysis { HashSet setRetNodes, OwnershipGraph og) throws java.io.IOException { - TempDescriptor src; - TempDescriptor dst; + TempDescriptor lhs; + TempDescriptor rhs; FieldDescriptor fld; // use node type to decide what alterations to make @@ -441,9 +444,9 @@ public class OwnershipAnalysis { // adding parameters labels to new heap regions for( int i = 0; i < fm.numParameters(); ++i ) { TempDescriptor tdParam = fm.getParameter(i); - og.assignParameterAllocationToTemp(methodDesc instanceof TaskDescriptor, - tdParam, - new Integer(i) ); + og.assignTempEqualToParamAlloc(tdParam, + methodDesc instanceof TaskDescriptor, + new Integer(i) ); } break; @@ -451,36 +454,36 @@ public class OwnershipAnalysis { case FKind.FlatOpNode: FlatOpNode fon = (FlatOpNode) fn; if( fon.getOp().getOp() == Operation.ASSIGN ) { - src = fon.getLeft(); - dst = fon.getDest(); - og.assignTempYToTempX(src, dst); + lhs = fon.getLeft(); + rhs = fon.getDest(); + og.assignTempXEqualToTempY(lhs, rhs); } break; case FKind.FlatFieldNode: FlatFieldNode ffn = (FlatFieldNode) fn; - src = ffn.getSrc(); - dst = ffn.getDst(); + lhs = ffn.getSrc(); + rhs = ffn.getDst(); fld = ffn.getField(); if( !fld.getType().isPrimitive() ) { - og.assignTempYFieldFToTempX(src, fld, dst); + og.assignTempXEqualToTempYFieldF(lhs, rhs, fld); } break; case FKind.FlatSetFieldNode: FlatSetFieldNode fsfn = (FlatSetFieldNode) fn; - src = fsfn.getSrc(); - dst = fsfn.getDst(); + lhs = fsfn.getSrc(); fld = fsfn.getField(); - og.assignTempYToTempXFieldF(src, dst, fld); + rhs = fsfn.getDst(); + og.assignTempXFieldFEqualToTempY(lhs, fld, rhs); break; case FKind.FlatNew: FlatNew fnn = (FlatNew) fn; - dst = fnn.getDst(); + lhs = fnn.getDst(); AllocationSite as = getAllocationSiteFromFlatNewPRIVATE(fnn); - og.assignNewAllocationToTempX(dst, as); + og.assignTempEqualToNewAlloc(lhs, as); break; case FKind.FlatCall: @@ -508,7 +511,7 @@ public class OwnershipAnalysis { ogAllPossibleCallees.merge(ogPotentialCallee); } } - + // Now we should have the following information to resolve this method call: // // 1. A FlatCall fc to query for the caller's context (argument labels, etc) @@ -528,6 +531,12 @@ public class OwnershipAnalysis { case FKind.FlatReturnNode: FlatReturnNode frn = (FlatReturnNode) fn; + rhs = frn.getReturnTemp(); + + if( rhs != null ) { + og.assignReturnEqualToTemp(rhs); + } + setRetNodes.add(frn); break; } diff --git a/Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java b/Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java index 2529c0c5..ceddf6bd 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java +++ b/Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java @@ -26,6 +26,9 @@ public class OwnershipGraph { public HashSet allocationSites; + protected static TempDescriptor lnReturn = new TempDescriptor("_Return___"); + + public OwnershipGraph(int allocationDepth) { this.allocationDepth = allocationDepth; @@ -338,8 +341,8 @@ public class OwnershipGraph { // of the nodes and edges involved. // //////////////////////////////////////////////////// - public void assignTempYToTempX(TempDescriptor y, - TempDescriptor x) { + public void assignTempXEqualToTempY(TempDescriptor x, + TempDescriptor y) { LabelNode lnX = getLabelNodeFromTemp(x); LabelNode lnY = getLabelNodeFromTemp(y); @@ -358,9 +361,9 @@ public class OwnershipGraph { } - public void assignTempYFieldFToTempX(TempDescriptor y, - FieldDescriptor f, - TempDescriptor x) { + public void assignTempXEqualToTempYFieldF(TempDescriptor x, + TempDescriptor y, + FieldDescriptor f) { LabelNode lnX = getLabelNodeFromTemp(x); LabelNode lnY = getLabelNodeFromTemp(y); @@ -395,9 +398,9 @@ public class OwnershipGraph { } - public void assignTempYToTempXFieldF(TempDescriptor y, - TempDescriptor x, - FieldDescriptor f) { + public void assignTempXFieldFEqualToTempY(TempDescriptor x, + FieldDescriptor f, + TempDescriptor y) { LabelNode lnX = getLabelNodeFromTemp(x); LabelNode lnY = getLabelNodeFromTemp(y); @@ -505,20 +508,20 @@ public class OwnershipGraph { } - public void assignParameterAllocationToTemp(boolean isTask, - TempDescriptor td, - Integer paramIndex) { + public void assignTempEqualToParamAlloc(TempDescriptor td, + boolean isTask, + Integer paramIndex) { assert td != null; LabelNode lnParam = getLabelNodeFromTemp(td); HeapRegionNode hrn = createNewHeapRegionNode(null, - false, - isTask, - false, - true, - null, - null, - "param" + paramIndex); + false, + isTask, + false, + true, + null, + null, + "param" + paramIndex); // this is a non-program-accessible label that picks up beta // info to be used for fixing a caller of this method @@ -559,8 +562,27 @@ public class OwnershipGraph { } - public void assignNewAllocationToTempX(TempDescriptor x, - AllocationSite as) { + public void assignReturnEqualToTemp(TempDescriptor x) { + + LabelNode lnR = getLabelNodeFromTemp(lnReturn); + LabelNode lnX = getLabelNodeFromTemp(x); + + clearReferenceEdgesFrom(lnR, null, true); + + Iterator itrXhrn = lnX.iteratorToReferencees(); + while( itrXhrn.hasNext() ) { + ReferenceEdge edgeX = itrXhrn.next(); + HeapRegionNode referencee = edgeX.getDst(); + ReferenceEdge edgeNew = edgeX.copy(); + edgeNew.setSrc(lnR); + + addReferenceEdge(lnR, referencee, edgeNew); + } + } + + + public void assignTempEqualToNewAlloc(TempDescriptor x, + AllocationSite as) { assert x != null; assert as != null; @@ -866,7 +888,7 @@ public class OwnershipGraph { FlatMethod fm, OwnershipGraph ogCallee) { - + // define rewrite rules and other structures to organize // data by parameter/argument index Hashtable paramIndex2rewriteH = @@ -903,76 +925,77 @@ public class OwnershipGraph { // add a bogus entry with the identity rule for easy rewrite // of new callee nodes and edges, doesn't belong to any parameter - Integer bogusID = new Integer( -1 ); - Integer bogusIndex = new Integer( -1 ); - TokenTuple bogusToken = new TokenTuple( bogusID, true, TokenTuple.ARITY_ONE ); - TokenTuple bogusTokenStar = new TokenTuple( bogusID, true, TokenTuple.ARITY_MANY ); - ReachabilitySet rsIdentity = - new ReachabilitySet( new TokenTupleSet( bogusToken ).makeCanonical() ).makeCanonical(); + Integer bogusID = new Integer(-1); + Integer bogusIndex = new Integer(-1); + TokenTuple bogusToken = new TokenTuple(bogusID, true, TokenTuple.ARITY_ONE); + TokenTuple bogusTokenStar = new TokenTuple(bogusID, true, TokenTuple.ARITY_MANY); + ReachabilitySet rsIdentity = + new ReachabilitySet(new TokenTupleSet(bogusToken).makeCanonical() ).makeCanonical(); - paramIndex2rewriteH.put( bogusIndex, rsIdentity ); - paramIndex2rewriteJ.put( bogusIndex, rsIdentity ); - paramToken2paramIndex.put( bogusToken, bogusIndex ); - paramIndex2paramToken.put( bogusIndex, bogusToken ); - paramTokenStar2paramIndex.put( bogusTokenStar, bogusIndex ); - paramIndex2paramTokenStar.put( bogusIndex, bogusTokenStar ); + paramIndex2rewriteH.put(bogusIndex, rsIdentity); + paramIndex2rewriteJ.put(bogusIndex, rsIdentity); + paramToken2paramIndex.put(bogusToken, bogusIndex); + paramIndex2paramToken.put(bogusIndex, bogusToken); + paramTokenStar2paramIndex.put(bogusTokenStar, bogusIndex); + paramIndex2paramTokenStar.put(bogusIndex, bogusTokenStar); for( int i = 0; i < fm.numParameters(); ++i ) { - Integer paramIndex = new Integer( i ); - - assert ogCallee.paramIndex2id.containsKey( paramIndex ); - Integer idParam = ogCallee.paramIndex2id.get( paramIndex ); - - assert ogCallee.id2hrn.containsKey( idParam ); - HeapRegionNode hrnParam = ogCallee.id2hrn.get( idParam ); + Integer paramIndex = new Integer(i); + + assert ogCallee.paramIndex2id.containsKey(paramIndex); + Integer idParam = ogCallee.paramIndex2id.get(paramIndex); + + assert ogCallee.id2hrn.containsKey(idParam); + HeapRegionNode hrnParam = ogCallee.id2hrn.get(idParam); assert hrnParam != null; - paramIndex2rewriteH.put( paramIndex, - toShadowTokens( ogCallee, hrnParam.getAlpha() ) - ); + paramIndex2rewriteH.put(paramIndex, + + toShadowTokens(ogCallee, hrnParam.getAlpha() ) + ); - ReferenceEdge edgeReflexive_i = hrnParam.getReferenceTo( hrnParam, null ); + ReferenceEdge edgeReflexive_i = hrnParam.getReferenceTo(hrnParam, null); assert edgeReflexive_i != null; - paramIndex2rewriteJ.put( paramIndex, - toShadowTokens( ogCallee, edgeReflexive_i.getBeta() ) - ); + paramIndex2rewriteJ.put(paramIndex, + toShadowTokens(ogCallee, edgeReflexive_i.getBeta() ) + ); - TempDescriptor tdParamQ = ogCallee.paramIndex2tdQ.get( paramIndex ); + TempDescriptor tdParamQ = ogCallee.paramIndex2tdQ.get(paramIndex); assert tdParamQ != null; - LabelNode lnParamQ = ogCallee.td2ln.get( tdParamQ ); + LabelNode lnParamQ = ogCallee.td2ln.get(tdParamQ); assert lnParamQ != null; - ReferenceEdge edgeSpecialQ_i = lnParamQ.getReferenceTo( hrnParam, null ); + ReferenceEdge edgeSpecialQ_i = lnParamQ.getReferenceTo(hrnParam, null); assert edgeSpecialQ_i != null; - paramIndex2rewriteK.put( paramIndex, - toShadowTokens( ogCallee, edgeSpecialQ_i.getBeta() ) - ); - - TokenTuple p_i = new TokenTuple( hrnParam.getID(), - true, - TokenTuple.ARITY_ONE ).makeCanonical(); - paramToken2paramIndex.put( p_i, paramIndex ); - paramIndex2paramToken.put( paramIndex, p_i ); - - TokenTuple p_i_star = new TokenTuple( hrnParam.getID(), - true, - TokenTuple.ARITY_MANY ).makeCanonical(); - paramTokenStar2paramIndex.put( p_i_star, paramIndex ); - paramIndex2paramTokenStar.put( paramIndex, p_i_star ); + paramIndex2rewriteK.put(paramIndex, + toShadowTokens(ogCallee, edgeSpecialQ_i.getBeta() ) + ); + + TokenTuple p_i = new TokenTuple(hrnParam.getID(), + true, + TokenTuple.ARITY_ONE).makeCanonical(); + paramToken2paramIndex.put(p_i, paramIndex); + paramIndex2paramToken.put(paramIndex, p_i); + + TokenTuple p_i_star = new TokenTuple(hrnParam.getID(), + true, + TokenTuple.ARITY_MANY).makeCanonical(); + paramTokenStar2paramIndex.put(p_i_star, paramIndex); + paramIndex2paramTokenStar.put(paramIndex, p_i_star); // 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_i; if( isStatic ) { - argTemp_i = fc.getArg( paramIndex ); + argTemp_i = fc.getArg(paramIndex); } else { if( paramIndex == 0 ) { argTemp_i = fc.getThis(); } else { - argTemp_i = fc.getArg( paramIndex - 1 ); + argTemp_i = fc.getArg(paramIndex - 1); } } - + // in non-static methods there is a "this" pointer // that should be taken into account if( isStatic ) { @@ -980,21 +1003,21 @@ public class OwnershipGraph { } else { assert fc.numArgs() + 1 == fm.numParameters(); } - - LabelNode argLabel_i = getLabelNodeFromTemp( argTemp_i ); - paramIndex2ln.put( paramIndex, argLabel_i ); + + LabelNode argLabel_i = getLabelNodeFromTemp(argTemp_i); + paramIndex2ln.put(paramIndex, argLabel_i); ReachabilitySet D_i = new ReachabilitySet().makeCanonical(); Iterator edgeItr = argLabel_i.iteratorToReferencees(); while( edgeItr.hasNext() ) { ReferenceEdge edge = edgeItr.next(); - D_i = D_i.union( edge.getBeta() ); + D_i = D_i.union(edge.getBeta() ); } D_i = D_i.exhaustiveArityCombinations(); - paramIndex2rewriteD.put( paramIndex, D_i ); + paramIndex2rewriteD.put(paramIndex, D_i); } - + HashSet nodesWithNewAlpha = new HashSet(); HashSet edgesWithNewBeta = new HashSet(); @@ -1003,8 +1026,8 @@ public class OwnershipGraph { Iterator lnArgItr = paramIndex2ln.entrySet().iterator(); while( lnArgItr.hasNext() ) { - Map.Entry me = (Map.Entry) lnArgItr.next(); - Integer index = (Integer) me.getKey(); + Map.Entry me = (Map.Entry)lnArgItr.next(); + Integer index = (Integer) me.getKey(); LabelNode lnArg_i = (LabelNode) me.getValue(); // rewrite alpha for the nodes reachable from argument label i @@ -1015,27 +1038,27 @@ public class OwnershipGraph { Iterator edgeArgItr = lnArg_i.iteratorToReferencees(); while( edgeArgItr.hasNext() ) { ReferenceEdge edge = edgeArgItr.next(); - todoNodes.add( edge.getDst() ); + todoNodes.add(edge.getDst() ); } // then follow links until all reachable nodes have been found while( !todoNodes.isEmpty() ) { HeapRegionNode hrn = todoNodes.iterator().next(); - todoNodes.remove( hrn ); - reachableNodes.add( hrn ); + todoNodes.remove(hrn); + reachableNodes.add(hrn); Iterator edgeItr = hrn.iteratorToReferencees(); while( edgeItr.hasNext() ) { ReferenceEdge edge = edgeItr.next(); - if( !reachableNodes.contains( edge.getDst() ) ) { - todoNodes.add( edge.getDst() ); + if( !reachableNodes.contains(edge.getDst() ) ) { + todoNodes.add(edge.getDst() ); } - } + } } - + // save for later - paramIndex2reachableCallerNodes.put( index, reachableNodes ); + paramIndex2reachableCallerNodes.put(index, reachableNodes); // now iterate over reachable nodes to update their alpha, and // classify edges found as "argument reachable" or "upstream" @@ -1043,16 +1066,16 @@ public class OwnershipGraph { while( hrnItr.hasNext() ) { HeapRegionNode hrn = hrnItr.next(); - rewriteCallerNodeAlpha( fm.numParameters(), - index, - hrn, - paramIndex2rewriteH, - paramIndex2rewriteD, - paramIndex2paramToken, - paramIndex2paramTokenStar ); + rewriteCallerNodeAlpha(fm.numParameters(), + index, + hrn, + paramIndex2rewriteH, + paramIndex2rewriteD, + paramIndex2paramToken, + paramIndex2paramTokenStar); + + nodesWithNewAlpha.add(hrn); - nodesWithNewAlpha.add( hrn ); - // look at all incoming edges to the reachable nodes // and sort them as edges reachable from the argument // label node, or upstream edges @@ -1065,22 +1088,22 @@ public class OwnershipGraph { if( on instanceof LabelNode ) { LabelNode ln0 = (LabelNode) on; - if( ln0.equals( lnArg_i ) ) { - edgesReachable.add( edge ); - } else { - edgesUpstream.add( edge ); + if( ln0.equals(lnArg_i) ) { + edgesReachable.add(edge); + } else { + edgesUpstream.add(edge); } } else { HeapRegionNode hrn0 = (HeapRegionNode) on; - if( reachableNodes.contains( hrn0 ) ) { - edgesReachable.add( edge ); + if( reachableNodes.contains(hrn0) ) { + edgesReachable.add(edge); } else { - edgesUpstream.add( edge ); + edgesUpstream.add(edge); } } - } + } } @@ -1089,46 +1112,46 @@ public class OwnershipGraph { while( edgeReachableItr.hasNext() ) { ReferenceEdge edgeReachable = edgeReachableItr.next(); - rewriteCallerEdgeBeta( fm.numParameters(), - index, - edgeReachable, - paramIndex2rewriteJ, - paramIndex2rewriteD, - paramIndex2paramToken, - paramIndex2paramTokenStar, - false, - null ); - - edgesWithNewBeta.add( edgeReachable ); - } + rewriteCallerEdgeBeta(fm.numParameters(), + index, + edgeReachable, + paramIndex2rewriteJ, + paramIndex2rewriteD, + paramIndex2paramToken, + paramIndex2paramTokenStar, + false, + null); + + edgesWithNewBeta.add(edgeReachable); + } // update upstream edges Hashtable edgeUpstreamPlannedChanges - = new Hashtable(); + = new Hashtable(); Iterator edgeUpstreamItr = edgesUpstream.iterator(); while( edgeUpstreamItr.hasNext() ) { ReferenceEdge edgeUpstream = edgeUpstreamItr.next(); - rewriteCallerEdgeBeta( fm.numParameters(), - index, - edgeUpstream, - paramIndex2rewriteK, - paramIndex2rewriteD, - paramIndex2paramToken, - paramIndex2paramTokenStar, - true, - edgeUpstreamPlannedChanges ); - - edgesWithNewBeta.add( edgeUpstream ); + rewriteCallerEdgeBeta(fm.numParameters(), + index, + edgeUpstream, + paramIndex2rewriteK, + paramIndex2rewriteD, + paramIndex2paramToken, + paramIndex2paramTokenStar, + true, + edgeUpstreamPlannedChanges); + + edgesWithNewBeta.add(edgeUpstream); } - propagateTokensOverEdges( edgesUpstream, - edgeUpstreamPlannedChanges, - edgesWithNewBeta ); - } - + propagateTokensOverEdges(edgesUpstream, + edgeUpstreamPlannedChanges, + edgesWithNewBeta); + } + // commit changes to alpha and beta Iterator nodeItr = nodesWithNewAlpha.iterator(); @@ -1150,33 +1173,33 @@ public class OwnershipGraph { Iterator asItr = ogCallee.allocationSites.iterator(); while( asItr.hasNext() ) { AllocationSite allocSite = asItr.next(); - HeapRegionNode hrnSummary = getSummaryNode( allocSite ); - + HeapRegionNode hrnSummary = getSummaryNode(allocSite); + // assert that the shadow nodes have no reference edges // because they're brand new to the graph, or last time // they were used they should have been cleared of edges - HeapRegionNode hrnShadowSummary = getShadowSummaryNode( allocSite ); + HeapRegionNode hrnShadowSummary = getShadowSummaryNode(allocSite); assert hrnShadowSummary.getNumReferencers() == 0; assert hrnShadowSummary.getNumReferencees() == 0; // then bring g_ij onto g'_ij and rewrite - transferOnto( hrnSummary, hrnShadowSummary ); + transferOnto(hrnSummary, hrnShadowSummary); - HeapRegionNode hrnSummaryCallee = ogCallee.getSummaryNode( allocSite ); - hrnShadowSummary.setAlpha( toShadowTokens( ogCallee, hrnSummaryCallee.getAlpha() ) ); + HeapRegionNode hrnSummaryCallee = ogCallee.getSummaryNode(allocSite); + hrnShadowSummary.setAlpha(toShadowTokens(ogCallee, hrnSummaryCallee.getAlpha() ) ); // shadow nodes only are touched by a rewrite one time, // so rewrite and immediately commit--and they don't belong // to a particular parameter, so use a bogus param index // that pulls a self-rewrite out of H - rewriteCallerNodeAlpha( fm.numParameters(), - bogusIndex, - hrnShadowSummary, - paramIndex2rewriteH, - paramIndex2rewriteD, - paramIndex2paramToken, - paramIndex2paramTokenStar ); - + rewriteCallerNodeAlpha(fm.numParameters(), + bogusIndex, + hrnShadowSummary, + paramIndex2rewriteH, + paramIndex2rewriteD, + paramIndex2paramToken, + paramIndex2paramTokenStar); + hrnShadowSummary.applyAlphaNew(); @@ -1191,49 +1214,44 @@ public class OwnershipGraph { assert hrnIthShadow.getNumReferencers() == 0; assert hrnIthShadow.getNumReferencees() == 0; - transferOnto( hrnIth, hrnIthShadow ); - + transferOnto(hrnIth, hrnIthShadow); + assert ogCallee.id2hrn.containsKey(idIth); HeapRegionNode hrnIthCallee = ogCallee.id2hrn.get(idIth); - hrnIthShadow.setAlpha( toShadowTokens( ogCallee, hrnIthCallee.getAlpha() ) ); + hrnIthShadow.setAlpha(toShadowTokens(ogCallee, hrnIthCallee.getAlpha() ) ); - rewriteCallerNodeAlpha( fm.numParameters(), - bogusIndex, - hrnIthShadow, - paramIndex2rewriteH, - paramIndex2rewriteD, - paramIndex2paramToken, - paramIndex2paramTokenStar ); + rewriteCallerNodeAlpha(fm.numParameters(), + bogusIndex, + hrnIthShadow, + paramIndex2rewriteH, + paramIndex2rewriteD, + paramIndex2paramToken, + paramIndex2paramTokenStar); hrnIthShadow.applyAlphaNew(); } } - - - try{ - writeGraph("test",true,true,true,false); - } catch(Exception e){} // for every heap region->heap region edge in the // callee graph, create the matching edge or edges // in the caller graph - Set sCallee = ogCallee.id2hrn.entrySet(); + Set sCallee = ogCallee.id2hrn.entrySet(); Iterator iCallee = sCallee.iterator(); while( iCallee.hasNext() ) { - Map.Entry meCallee = (Map.Entry) iCallee.next(); - Integer idCallee = (Integer) meCallee.getKey(); + Map.Entry meCallee = (Map.Entry)iCallee.next(); + Integer idCallee = (Integer) meCallee.getKey(); HeapRegionNode hrnCallee = (HeapRegionNode) meCallee.getValue(); - + Iterator heapRegionsItrCallee = hrnCallee.iteratorToReferencees(); while( heapRegionsItrCallee.hasNext() ) { ReferenceEdge edgeCallee = heapRegionsItrCallee.next(); - HeapRegionNode hrnChildCallee = edgeCallee.getDst(); + HeapRegionNode hrnChildCallee = edgeCallee.getDst(); Integer idChildCallee = hrnChildCallee.getID(); - + // only address this edge if it is not a special reflexive edge if( !edgeCallee.isInitialParamReflexive() ) { - + // now we know that in the callee method's ownership graph // there is a heap region->heap region reference edge given // by heap region pointers: @@ -1244,21 +1262,21 @@ public class OwnershipGraph { // make the edge with src and dst so beta info is // calculated once, then copy it for each new edge in caller - ReferenceEdge edgeNewInCallerTemplate = new ReferenceEdge( null, - null, - edgeCallee.getFieldDesc(), - false, - toShadowTokens( ogCallee, edgeCallee.getBeta() ) - ); - rewriteCallerEdgeBeta( fm.numParameters(), - bogusIndex, - edgeNewInCallerTemplate, - paramIndex2rewriteJ, - paramIndex2rewriteD, - paramIndex2paramToken, - paramIndex2paramTokenStar, - false, - null ); + ReferenceEdge edgeNewInCallerTemplate = new ReferenceEdge(null, + null, + edgeCallee.getFieldDesc(), + false, + toShadowTokens(ogCallee, edgeCallee.getBeta() ) + ); + rewriteCallerEdgeBeta(fm.numParameters(), + bogusIndex, + edgeNewInCallerTemplate, + paramIndex2rewriteJ, + paramIndex2rewriteD, + paramIndex2paramToken, + paramIndex2paramTokenStar, + false, + null); edgeNewInCallerTemplate.applyBetaNew(); @@ -1268,37 +1286,37 @@ public class OwnershipGraph { // and a set of destination heaps in the caller graph, and make // a reference edge in the caller for every possible (src,dst) pair HashSet possibleCallerSrcs = - getHRNSetThatPossiblyMapToCalleeHRN( ogCallee, - edgeCallee, - true, - paramIndex2reachableCallerNodes ); - + getHRNSetThatPossiblyMapToCalleeHRN(ogCallee, + edgeCallee, + true, + paramIndex2reachableCallerNodes); + HashSet possibleCallerDsts = - getHRNSetThatPossiblyMapToCalleeHRN( ogCallee, - edgeCallee, - false, - paramIndex2reachableCallerNodes ); - + getHRNSetThatPossiblyMapToCalleeHRN(ogCallee, + edgeCallee, + false, + paramIndex2reachableCallerNodes); + // make every possible pair of {srcSet} -> {dstSet} edges in the caller Iterator srcItr = possibleCallerSrcs.iterator(); while( srcItr.hasNext() ) { HeapRegionNode src = (HeapRegionNode) srcItr.next(); - + Iterator dstItr = possibleCallerDsts.iterator(); while( dstItr.hasNext() ) { HeapRegionNode dst = (HeapRegionNode) dstItr.next(); - + ReferenceEdge edgeNewInCaller = edgeNewInCallerTemplate.copy(); - edgeNewInCaller.setSrc( src ); - edgeNewInCaller.setDst( dst ); - - ReferenceEdge edgeExisting = src.getReferenceTo( dst, edgeNewInCaller.getFieldDesc() ); + edgeNewInCaller.setSrc(src); + edgeNewInCaller.setDst(dst); + + ReferenceEdge edgeExisting = src.getReferenceTo(dst, edgeNewInCaller.getFieldDesc() ); if( edgeExisting == null ) { // if this edge doesn't exist in the caller, create it - addReferenceEdge( src, dst, edgeNewInCaller ); + addReferenceEdge(src, dst, edgeNewInCaller); } else { // if it already exists, merge with it - edgeExisting.setBeta( edgeExisting.getBeta().union( edgeNewInCaller.getBeta() ) ); + edgeExisting.setBeta(edgeExisting.getBeta().union(edgeNewInCaller.getBeta() ) ); } } } @@ -1314,59 +1332,59 @@ public class OwnershipGraph { // first age each allocation site enough times to make room for the shadow nodes for( int i = 0; i < as.getAllocationDepth(); ++i ) { - age( as ); + age(as); } // then merge the shadow summary into the normal summary - HeapRegionNode hrnSummary = getSummaryNode( as ); + HeapRegionNode hrnSummary = getSummaryNode(as); assert hrnSummary != null; - HeapRegionNode hrnSummaryShadow = getShadowSummaryNode( as ); + HeapRegionNode hrnSummaryShadow = getShadowSummaryNode(as); assert hrnSummaryShadow != null; - mergeIntoSummary( hrnSummaryShadow, hrnSummary ); + mergeIntoSummary(hrnSummaryShadow, hrnSummary); // then transplant shadow nodes onto the now clean normal nodes for( int i = 0; i < as.getAllocationDepth(); ++i ) { - + Integer idIth = as.getIthOldest(i); HeapRegionNode hrnIth = id2hrn.get(idIth); Integer idIthShadow = as.getIthOldestShadow(i); HeapRegionNode hrnIthShadow = id2hrn.get(idIthShadow); - + transferOnto(hrnIthShadow, hrnIth); - + // clear off shadow nodes after transfer clearReferenceEdgesFrom(hrnIthShadow, null, true); clearReferenceEdgesTo(hrnIthShadow, null, true); - hrnIthShadow.setAlpha( new ReachabilitySet().makeCanonical() ); - } + hrnIthShadow.setAlpha(new ReachabilitySet().makeCanonical() ); + } // finally, globally change shadow tokens into normal tokens Iterator itrAllLabelNodes = td2ln.entrySet().iterator(); while( itrAllLabelNodes.hasNext() ) { Map.Entry me = (Map.Entry)itrAllLabelNodes.next(); LabelNode ln = (LabelNode) me.getValue(); - + Iterator itrEdges = ln.iteratorToReferencees(); while( itrEdges.hasNext() ) { unshadowTokens(as, itrEdges.next() ); } } - + Iterator itrAllHRNodes = id2hrn.entrySet().iterator(); while( itrAllHRNodes.hasNext() ) { Map.Entry me = (Map.Entry)itrAllHRNodes.next(); HeapRegionNode hrnToAge = (HeapRegionNode) me.getValue(); - + unshadowTokens(as, hrnToAge); - + Iterator itrEdges = hrnToAge.iteratorToReferencees(); while( itrEdges.hasNext() ) { unshadowTokens(as, itrEdges.next() ); } - } + } } } @@ -1380,76 +1398,76 @@ public class OwnershipGraph { } - private ReachabilitySet toShadowTokens( OwnershipGraph ogCallee, - ReachabilitySet rsIn ) { + private ReachabilitySet toShadowTokens(OwnershipGraph ogCallee, + ReachabilitySet rsIn) { - ReachabilitySet rsOut = new ReachabilitySet( rsIn ); + ReachabilitySet rsOut = new ReachabilitySet(rsIn); Iterator allocItr = ogCallee.allocationSites.iterator(); while( allocItr.hasNext() ) { AllocationSite as = allocItr.next(); - rsOut = rsOut.toShadowTokens( as ); + rsOut = rsOut.toShadowTokens(as); } return rsOut.makeCanonical(); } - private void rewriteCallerNodeAlpha( int numParameters, - Integer paramIndex, - HeapRegionNode hrn, - Hashtable paramIndex2rewriteH, - Hashtable paramIndex2rewriteD, - Hashtable paramIndex2paramToken, - Hashtable paramIndex2paramTokenStar ) { - - ReachabilitySet rules = paramIndex2rewriteH.get( paramIndex ); + private void rewriteCallerNodeAlpha(int numParameters, + Integer paramIndex, + HeapRegionNode hrn, + Hashtable paramIndex2rewriteH, + Hashtable paramIndex2rewriteD, + Hashtable paramIndex2paramToken, + Hashtable paramIndex2paramTokenStar) { + + ReachabilitySet rules = paramIndex2rewriteH.get(paramIndex); assert rules != null; - TokenTuple tokenToRewrite = paramIndex2paramToken.get( paramIndex ); + TokenTuple tokenToRewrite = paramIndex2paramToken.get(paramIndex); assert tokenToRewrite != null; - ReachabilitySet r0 = new ReachabilitySet().makeCanonical(); + ReachabilitySet r0 = new ReachabilitySet().makeCanonical(); Iterator ttsItr = rules.iterator(); while( ttsItr.hasNext() ) { TokenTupleSet tts = ttsItr.next(); - r0 = r0.union( tts.rewriteToken( tokenToRewrite, - hrn.getAlpha(), - false, - null ) ); + r0 = r0.union(tts.rewriteToken(tokenToRewrite, + hrn.getAlpha(), + false, + null) ); } - + ReachabilitySet r1 = new ReachabilitySet().makeCanonical(); ttsItr = r0.iterator(); while( ttsItr.hasNext() ) { TokenTupleSet tts = ttsItr.next(); - r1 = r1.union( rewriteDpass( numParameters, - paramIndex, - tts, - paramIndex2rewriteD, - paramIndex2paramToken, - paramIndex2paramTokenStar ) ); - } - - hrn.setAlphaNew( hrn.getAlphaNew().union( r1 ) ); + r1 = r1.union(rewriteDpass(numParameters, + paramIndex, + tts, + paramIndex2rewriteD, + paramIndex2paramToken, + paramIndex2paramTokenStar) ); + } + + hrn.setAlphaNew(hrn.getAlphaNew().union(r1) ); } - private void rewriteCallerEdgeBeta( int numParameters, - Integer paramIndex, - ReferenceEdge edge, - Hashtable paramIndex2rewriteJorK, - Hashtable paramIndex2rewriteD, - Hashtable paramIndex2paramToken, - Hashtable paramIndex2paramTokenStar, - boolean makeChangeSet, - Hashtable edgePlannedChanges) { - - ReachabilitySet rules = paramIndex2rewriteJorK.get( paramIndex ); + private void rewriteCallerEdgeBeta(int numParameters, + Integer paramIndex, + ReferenceEdge edge, + Hashtable paramIndex2rewriteJorK, + Hashtable paramIndex2rewriteD, + Hashtable paramIndex2paramToken, + Hashtable paramIndex2paramTokenStar, + boolean makeChangeSet, + Hashtable edgePlannedChanges) { + + ReachabilitySet rules = paramIndex2rewriteJorK.get(paramIndex); assert rules != null; - TokenTuple tokenToRewrite = paramIndex2paramToken.get( paramIndex ); + TokenTuple tokenToRewrite = paramIndex2paramToken.get(paramIndex); assert tokenToRewrite != null; ChangeTupleSet cts0 = new ChangeTupleSet().makeCanonical(); @@ -1459,28 +1477,28 @@ public class OwnershipGraph { TokenTupleSet tts = ttsItr.next(); Hashtable forChangeSet = - new Hashtable(); - - ReachabilitySet rTemp = tts.rewriteToken( tokenToRewrite, - edge.getBeta(), - true, - forChangeSet ); + new Hashtable(); + + ReachabilitySet rTemp = tts.rewriteToken(tokenToRewrite, + edge.getBeta(), + true, + forChangeSet); Iterator fcsItr = forChangeSet.entrySet().iterator(); while( fcsItr.hasNext() ) { - Map.Entry me = (Map.Entry) fcsItr.next(); + Map.Entry me = (Map.Entry)fcsItr.next(); TokenTupleSet ttsMatch = (TokenTupleSet) me.getKey(); TokenTupleSet ttsAdd = (TokenTupleSet) me.getValue(); - - ChangeTuple ct = new ChangeTuple( ttsMatch, - ttsAdd - ).makeCanonical(); - - cts0 = cts0.union( ct ); + + ChangeTuple ct = new ChangeTuple(ttsMatch, + ttsAdd + ).makeCanonical(); + + cts0 = cts0.union(ct); } } - + ReachabilitySet r1 = new ReachabilitySet().makeCanonical(); ChangeTupleSet cts1 = new ChangeTupleSet().makeCanonical(); @@ -1488,115 +1506,115 @@ public class OwnershipGraph { while( ctItr.hasNext() ) { ChangeTuple ct = ctItr.next(); - ReachabilitySet rTemp = rewriteDpass( numParameters, - paramIndex, - ct.getSetToAdd(), - paramIndex2rewriteD, - paramIndex2paramToken, - paramIndex2paramTokenStar - ).makeCanonical(); - r1 = r1.union( rTemp ); - + ReachabilitySet rTemp = rewriteDpass(numParameters, + paramIndex, + ct.getSetToAdd(), + paramIndex2rewriteD, + paramIndex2paramToken, + paramIndex2paramTokenStar + ).makeCanonical(); + r1 = r1.union(rTemp); + if( makeChangeSet ) { assert edgePlannedChanges != null; - + Iterator ttsTempItr = rTemp.iterator(); while( ttsTempItr.hasNext() ) { TokenTupleSet tts = ttsTempItr.next(); - ChangeTuple ctFinal = new ChangeTuple( ct.getSetToMatch(), - tts - ).makeCanonical(); + ChangeTuple ctFinal = new ChangeTuple(ct.getSetToMatch(), + tts + ).makeCanonical(); - cts1 = cts1.union( ctFinal ); + cts1 = cts1.union(ctFinal); } } } if( makeChangeSet ) { - edgePlannedChanges.put( edge, cts1 ); + edgePlannedChanges.put(edge, cts1); } - edge.setBetaNew( edge.getBetaNew().union( r1 ) ); + edge.setBetaNew(edge.getBetaNew().union(r1) ); } - private ReachabilitySet rewriteDpass( int numParameters, - Integer paramIndex, - TokenTupleSet ttsIn, - Hashtable paramIndex2rewriteD, - Hashtable paramIndex2paramToken, - Hashtable paramIndex2paramTokenStar ) { + private ReachabilitySet rewriteDpass(int numParameters, + Integer paramIndex, + TokenTupleSet ttsIn, + Hashtable paramIndex2rewriteD, + Hashtable paramIndex2paramToken, + Hashtable paramIndex2paramTokenStar) { ReachabilitySet rsOut = new ReachabilitySet().makeCanonical(); boolean rewritten = false; for( int j = 0; j < numParameters; ++j ) { - Integer paramIndexJ = new Integer( j ); - ReachabilitySet D_j = paramIndex2rewriteD.get( paramIndexJ ); + Integer paramIndexJ = new Integer(j); + ReachabilitySet D_j = paramIndex2rewriteD.get(paramIndexJ); assert D_j != null; - + if( paramIndexJ != paramIndex ) { - TokenTuple tokenToRewriteJ = paramIndex2paramToken.get( paramIndexJ ); + TokenTuple tokenToRewriteJ = paramIndex2paramToken.get(paramIndexJ); assert tokenToRewriteJ != null; - if( ttsIn.containsTuple( tokenToRewriteJ ) ) { - ReachabilitySet r = ttsIn.rewriteToken( tokenToRewriteJ, - D_j, - false, - null ); + if( ttsIn.containsTuple(tokenToRewriteJ) ) { + ReachabilitySet r = ttsIn.rewriteToken(tokenToRewriteJ, + D_j, + false, + null); Iterator ttsItr = r.iterator(); while( ttsItr.hasNext() ) { TokenTupleSet tts = ttsItr.next(); - rsOut = rsOut.union( rewriteDpass( numParameters, - paramIndex, - tts, - paramIndex2rewriteD, - paramIndex2paramToken, - paramIndex2paramTokenStar ) ); + rsOut = rsOut.union(rewriteDpass(numParameters, + paramIndex, + tts, + paramIndex2rewriteD, + paramIndex2paramToken, + paramIndex2paramTokenStar) ); rewritten = true; - } + } } } - - TokenTuple tokenStarToRewriteJ = paramIndex2paramTokenStar.get( paramIndexJ ); - assert tokenStarToRewriteJ != null; - if( ttsIn.containsTuple( tokenStarToRewriteJ ) ) { - ReachabilitySet r = ttsIn.rewriteToken( tokenStarToRewriteJ, - D_j, - false, - null ); + + TokenTuple tokenStarToRewriteJ = paramIndex2paramTokenStar.get(paramIndexJ); + assert tokenStarToRewriteJ != null; + if( ttsIn.containsTuple(tokenStarToRewriteJ) ) { + ReachabilitySet r = ttsIn.rewriteToken(tokenStarToRewriteJ, + D_j, + false, + null); Iterator ttsItr = r.iterator(); while( ttsItr.hasNext() ) { TokenTupleSet tts = ttsItr.next(); - rsOut = rsOut.union( rewriteDpass( numParameters, - paramIndex, - tts, - paramIndex2rewriteD, - paramIndex2paramToken, - paramIndex2paramTokenStar ) ); + rsOut = rsOut.union(rewriteDpass(numParameters, + paramIndex, + tts, + paramIndex2rewriteD, + paramIndex2paramToken, + paramIndex2paramTokenStar) ); rewritten = true; } } } if( !rewritten ) { - rsOut = rsOut.union( ttsIn ); + rsOut = rsOut.union(ttsIn); } - + return rsOut; } - private HashSet - getHRNSetThatPossiblyMapToCalleeHRN( OwnershipGraph ogCallee, - ReferenceEdge edgeCallee, - boolean mapFromSrc, - Hashtable > paramIndex2reachableCallerNodes - ) { - + private HashSet + getHRNSetThatPossiblyMapToCalleeHRN(OwnershipGraph ogCallee, + ReferenceEdge edgeCallee, + boolean mapFromSrc, + Hashtable > paramIndex2reachableCallerNodes + ) { + HashSet possibleCallerHRNs = new HashSet(); - + HeapRegionNode hrnCallee; if( mapFromSrc ) { OwnershipNode on = edgeCallee.getSrc(); @@ -1606,7 +1624,7 @@ public class OwnershipGraph { hrnCallee = edgeCallee.getDst(); } - Integer paramIndexCallee = ogCallee.id2paramIndex.get( hrnCallee.getID() ); + Integer paramIndexCallee = ogCallee.id2paramIndex.get(hrnCallee.getID() ); if( paramIndexCallee == null ) { // this is a node allocated in the callee then and it has @@ -1614,7 +1632,7 @@ public class OwnershipGraph { AllocationSite as = hrnCallee.getAllocationSite(); assert as != null; - int age = as.getAgeCategory( hrnCallee.getID() ); + int age = as.getAgeCategory(hrnCallee.getID() ); assert age != AllocationSite.AGE_notInThisSite; Integer idCaller; @@ -1625,28 +1643,28 @@ public class OwnershipGraph { } else { assert age == AllocationSite.AGE_in_I; - Integer I = as.getAge( hrnCallee.getID() ); + Integer I = as.getAge(hrnCallee.getID() ); assert I != null; - - idCaller = as.getIthOldestShadow( I ); + + idCaller = as.getIthOldestShadow(I); } - assert id2hrn.containsKey( idCaller ); - HeapRegionNode hrnCaller = id2hrn.get( idCaller ); - possibleCallerHRNs.add( hrnCaller ); - + assert id2hrn.containsKey(idCaller); + HeapRegionNode hrnCaller = id2hrn.get(idCaller); + possibleCallerHRNs.add(hrnCaller); + } else { // this is a node that was created to represent a parameter // so it maps to a whole mess of heap regions - assert paramIndex2reachableCallerNodes.containsKey( paramIndexCallee ); - possibleCallerHRNs = paramIndex2reachableCallerNodes.get( paramIndexCallee ); + assert paramIndex2reachableCallerNodes.containsKey(paramIndexCallee); + possibleCallerHRNs = paramIndex2reachableCallerNodes.get(paramIndexCallee); // TODO PRUNE BY TYPE/FIELD NAME!! } return possibleCallerHRNs; } - + //////////////////////////////////////////////////// @@ -2211,12 +2229,13 @@ public class OwnershipGraph { ); } - public void writeGraph(Descriptor methodDesc, + /* + public void writeGraph(Descriptor methodDesc, FlatNode fn, boolean writeLabels, boolean writeReferencers ) throws java.io.IOException { - writeGraph( + writeGraph( methodDesc.getSymbol() + methodDesc.getNum() + fn.toString(), @@ -2225,13 +2244,13 @@ public class OwnershipGraph { false, writeReferencers ); - } + } - public void writeGraph(Descriptor methodDesc, + public void writeGraph(Descriptor methodDesc, boolean writeLabels, boolean writeReferencers ) throws java.io.IOException { - writeGraph( + writeGraph( methodDesc.getSymbol() + methodDesc.getNum() + "COMPLETE", @@ -2240,7 +2259,8 @@ public class OwnershipGraph { false, writeReferencers ); - } + } + */ public void writeGraph(Descriptor methodDesc, boolean writeLabels, @@ -2248,15 +2268,13 @@ public class OwnershipGraph { boolean pruneGarbage, boolean writeReferencers ) throws java.io.IOException { - writeGraph( - methodDesc.getSymbol() + - methodDesc.getNum() + - "COMPLETE", - writeLabels, - labelSelect, - pruneGarbage, - writeReferencers - ); + + writeGraph(methodDesc+"COMPLETE", + writeLabels, + labelSelect, + pruneGarbage, + writeReferencers + ); } public void writeGraph(String graphName, diff --git a/Robust/src/Analysis/OwnershipAnalysis/ReachabilitySet.java b/Robust/src/Analysis/OwnershipAnalysis/ReachabilitySet.java index 2fa693b1..4409a99b 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/ReachabilitySet.java +++ b/Robust/src/Analysis/OwnershipAnalysis/ReachabilitySet.java @@ -174,7 +174,7 @@ public class ReachabilitySet extends Canonical { Iterator itrS = this.iterator(); while( itrS.hasNext() ) { TokenTupleSet tts = (TokenTupleSet) itrS.next(); - rsOut.possibleReachabilities.add( tts.ageTokens(as) ); + rsOut.possibleReachabilities.add(tts.ageTokens(as) ); } return rsOut.makeCanonical(); @@ -189,11 +189,11 @@ public class ReachabilitySet extends Canonical { Iterator itrS = this.iterator(); while( itrS.hasNext() ) { TokenTupleSet tts = (TokenTupleSet) itrS.next(); - rsOut.possibleReachabilities.add( tts.unshadowTokens(as) ); + rsOut.possibleReachabilities.add(tts.unshadowTokens(as) ); } return rsOut.makeCanonical(); - } + } public ReachabilitySet toShadowTokens(AllocationSite as) { @@ -204,7 +204,7 @@ public class ReachabilitySet extends Canonical { Iterator itrS = this.iterator(); while( itrS.hasNext() ) { TokenTupleSet tts = (TokenTupleSet) itrS.next(); - rsOut.possibleReachabilities.add( tts.toShadowTokens(as) ); + rsOut.possibleReachabilities.add(tts.toShadowTokens(as) ); } return rsOut.makeCanonical(); @@ -243,7 +243,7 @@ public class ReachabilitySet extends Canonical { public ReachabilitySet exhaustiveArityCombinations() { ReachabilitySet rsOut = new ReachabilitySet(); - int numDimensions = this.possibleReachabilities.size(); + int numDimensions = this.possibleReachabilities.size(); // add an extra digit to detect termination int[] digits = new int[numDimensions+1]; @@ -258,7 +258,7 @@ public class ReachabilitySet extends Canonical { // and stop when the highest-ordered axis rolls above the minimum while( digits[numDimensions] == minArity ) { - + // spit out a "coordinate" made from these digits TokenTupleSet ttsCoordinate = new TokenTupleSet(); Iterator ttsItr = this.iterator(); @@ -266,22 +266,22 @@ public class ReachabilitySet extends Canonical { assert ttsItr.hasNext(); TokenTupleSet ttsUnit = ttsItr.next(); for( int j = 0; j < digits[i]; ++j ) { - ttsCoordinate = ttsCoordinate.unionUpArity( ttsUnit ); + ttsCoordinate = ttsCoordinate.unionUpArity(ttsUnit); } } - rsOut = rsOut.add( ttsCoordinate.makeCanonical() ); + rsOut = rsOut.add(ttsCoordinate.makeCanonical() ); // increment for( int i = 0; i < numDimensions+1; ++i ) { - digits[i]++; - if( digits[i] > maxArity ) { + digits[i]++; + if( digits[i] > maxArity ) { // this axis reached its max, so roll it back to min and increment next higher digit digits[i] = minArity; - - } else { + + } else { // this axis did not reach its max so we just enumerated a new unique coordinate, stop break; - } + } } } diff --git a/Robust/src/Analysis/OwnershipAnalysis/TokenTupleSet.java b/Robust/src/Analysis/OwnershipAnalysis/TokenTupleSet.java index 94053a4e..7efe6931 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/TokenTupleSet.java +++ b/Robust/src/Analysis/OwnershipAnalysis/TokenTupleSet.java @@ -58,7 +58,7 @@ public class TokenTupleSet extends Canonical { return ttsOut.makeCanonical(); } - public TokenTupleSet unionUpArity( TokenTupleSet ttsIn ) { + public TokenTupleSet unionUpArity(TokenTupleSet ttsIn) { assert ttsIn != null; TokenTupleSet ttsOut = new TokenTupleSet(); @@ -66,7 +66,7 @@ public class TokenTupleSet extends Canonical { while( ttItr.hasNext() ) { TokenTuple tt = ttItr.next(); - if( ttsIn.containsToken( tt.getToken() ) ) { + if( ttsIn.containsToken(tt.getToken() ) ) { ttsOut.tokenTuples.add(tt.increaseArity()); } else { ttsOut.tokenTuples.add(tt); @@ -82,7 +82,7 @@ public class TokenTupleSet extends Canonical { } } - return ttsOut.makeCanonical(); + return ttsOut.makeCanonical(); } public TokenTupleSet add(TokenTuple tt) { @@ -166,12 +166,12 @@ public class TokenTupleSet extends Canonical { // 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 an oldest token, again just remember // for later foundOldest = true; - + } else { assert age == AllocationSite.AGE_in_I; @@ -260,14 +260,14 @@ public class TokenTupleSet extends Canonical { } else if( ttSummary == null && foundShadowSummary ) { ttSummary = new TokenTuple(as.getSummary(), - true, - TokenTuple.ARITY_ONE).makeCanonical(); - ttsOut.tokenTuples.add( ttSummary ); + true, + TokenTuple.ARITY_ONE).makeCanonical(); + ttsOut.tokenTuples.add(ttSummary); } else if( ttSummary != null && foundShadowSummary ) { ttsOut.tokenTuples.add(ttSummary.increaseArity() ); } - + return ttsOut.makeCanonical(); } @@ -290,10 +290,10 @@ public class TokenTupleSet extends Canonical { ttsOut.tokenTuples.add(tt); } else if( age == AllocationSite.AGE_summary ) { - ttsOut.tokenTuples.add(tt.changeTokenTo( as.getSummaryShadow() )); + ttsOut.tokenTuples.add(tt.changeTokenTo(as.getSummaryShadow() )); } else if( age == AllocationSite.AGE_oldest ) { - ttsOut.tokenTuples.add(tt.changeTokenTo( as.getOldestShadow() )); + ttsOut.tokenTuples.add(tt.changeTokenTo(as.getOldestShadow() )); } else { assert age == AllocationSite.AGE_in_I; @@ -301,7 +301,7 @@ public class TokenTupleSet extends Canonical { Integer I = as.getAge(token); assert I != null; - ttsOut.tokenTuples.add(tt.changeTokenTo( as.getIthOldestShadow( I ) )); + ttsOut.tokenTuples.add(tt.changeTokenTo(as.getIthOldestShadow(I) )); } } @@ -309,37 +309,37 @@ public class TokenTupleSet extends Canonical { } - public ReachabilitySet rewriteToken( TokenTuple tokenToRewrite, - ReachabilitySet replacements, - boolean makeChangeSet, - Hashtable forChangeSet ) { - + public ReachabilitySet rewriteToken(TokenTuple tokenToRewrite, + ReachabilitySet replacements, + boolean makeChangeSet, + Hashtable forChangeSet) { + ReachabilitySet rsOut = new ReachabilitySet().makeCanonical(); - - if( !tokenTuples.contains( tokenToRewrite ) ) { - rsOut = rsOut.add( this ); - + + if( !tokenTuples.contains(tokenToRewrite) ) { + rsOut = rsOut.add(this); + } else { - TokenTupleSet ttsMinusToken = new TokenTupleSet( this ); - ttsMinusToken.tokenTuples.remove( tokenToRewrite ); - + TokenTupleSet ttsMinusToken = new TokenTupleSet(this); + ttsMinusToken.tokenTuples.remove(tokenToRewrite); + Iterator replaceItr = replacements.iterator(); while( replaceItr.hasNext() ) { TokenTupleSet replacement = replaceItr.next(); - TokenTupleSet replaced = new TokenTupleSet( ttsMinusToken ); - replaced = replaced.unionUpArity( replacement ); - rsOut = rsOut.add( replaced ); + TokenTupleSet replaced = new TokenTupleSet(ttsMinusToken); + replaced = replaced.unionUpArity(replacement); + rsOut = rsOut.add(replaced); if( makeChangeSet ) { assert forChangeSet != null; - forChangeSet.put( this, replaced ); + forChangeSet.put(this, replaced); } } } - + return rsOut.makeCanonical(); } - + public String toString() { return tokenTuples.toString(); diff --git a/Robust/src/Runtime/DSTM/interface/dstm.h b/Robust/src/Runtime/DSTM/interface/dstm.h index d4091a22..993d730e 100644 --- a/Robust/src/Runtime/DSTM/interface/dstm.h +++ b/Robust/src/Runtime/DSTM/interface/dstm.h @@ -105,7 +105,7 @@ typedef struct objheader { (*((unsigned int *)&((struct ___Object___ *)((unsigned int) x + sizeof(objheader_t)))->___nextobject___)) #define COMPOID(x) \ - ((void*)((((void *) x )!=NULL)?(*((unsigned int *)&((struct ___Object___ *) x)->___nextobject___)):0)) + ((void*)((((void *) x )!=NULL) ? (*((unsigned int *)&((struct ___Object___ *) x)->___nextobject___)) : 0)) #define STATUS(x) \ *((unsigned int *) &(((struct ___Object___ *)((unsigned int) x + sizeof(objheader_t)))->___localcopy___)) diff --git a/Robust/src/Runtime/multicoretask.c b/Robust/src/Runtime/multicoretask.c index 06d36412..93375161 100644 --- a/Robust/src/Runtime/multicoretask.c +++ b/Robust/src/Runtime/multicoretask.c @@ -3404,7 +3404,7 @@ parameterpresent: }*/ /* Actually call task */ #ifdef PRECISE_GC - ((int *)taskpointerarray)[0]=currtpd->numParameters; + ((int *)taskpointerarray)[0]=currtpd->numParameters; taskpointerarray[1]=NULL; #endif execute: diff --git a/Robust/src/Runtime/task.c b/Robust/src/Runtime/task.c index fd325fd4..1d7403db 100644 --- a/Robust/src/Runtime/task.c +++ b/Robust/src/Runtime/task.c @@ -1200,7 +1200,7 @@ parameterpresent: } /* Actually call task */ #ifdef PRECISE_GC - ((int *)taskpointerarray)[0]=currtpd->numParameters; + ((int *)taskpointerarray)[0]=currtpd->numParameters; taskpointerarray[1]=NULL; #endif #ifdef OPTIONAL diff --git a/Robust/src/Tests/OwnershipAnalysisTest/test01/test01.java b/Robust/src/Tests/OwnershipAnalysisTest/test01/test01.java index ec7e604f..628bc6d6 100644 --- a/Robust/src/Tests/OwnershipAnalysisTest/test01/test01.java +++ b/Robust/src/Tests/OwnershipAnalysisTest/test01/test01.java @@ -20,11 +20,22 @@ public class Penguin { public void bar() { x = 1; } } - +*/ public class Voo { - flag f; int x; Baw b; Baw bb; - - public Voo() {} + flag f; int x; Baw b; Baw bb; + + public Voo() {} + + static Voo getAVoo( Voo bogus ) { + while( false ) { + if( false ) { + return new Voo(); + } else { + return new Voo(); + } + } + return new Voo(); + } } public class Baw { @@ -35,7 +46,7 @@ public class Baw { public void doTheBaw( Voo v ) { v = new Voo(); } } -*/ + public class Foo { flag f; @@ -347,6 +358,13 @@ task methodTest( Foo p0{ f } ) { */ +task getNewFromMethod( Foo p0{ f } ) { + Voo g = Voo.getAVoo( null ); + + taskexit( p0{ !f } ); +} + + task methodTest01_( Foo p0{ f }, Foo p1{ f } ) { Foo a0before = new Foo(); diff --git a/Robust/src/Tests/OwnershipAnalysisTest/test03/makefile b/Robust/src/Tests/OwnershipAnalysisTest/test03/makefile index 78e3c5bd..fdec30a9 100644 --- a/Robust/src/Tests/OwnershipAnalysisTest/test03/makefile +++ b/Robust/src/Tests/OwnershipAnalysisTest/test03/makefile @@ -3,7 +3,8 @@ PROGRAM=test03 SOURCE_FILES=$(PROGRAM).java BUILDSCRIPT=~/research/Robust/src/buildscript -BSFLAGS= -recover -flatirtasks -ownership -enable-assertions +#BSFLAGS= -recover -flatirtasks -ownership -enable-assertions +BSFLAGS= -recover -ownership -enable-assertions all: $(PROGRAM).bin @@ -11,7 +12,8 @@ view: PNGs eog *.png PNGs: DOTs - d2p *COMPLETE*.dot + #d2p *COMPLETE*.dot + d2p *.dot DOTs: $(PROGRAM).bin diff --git a/Robust/src/Tests/OwnershipAnalysisTest/test03/test03.java b/Robust/src/Tests/OwnershipAnalysisTest/test03/test03.java index 2ead68ea..0fce153f 100644 --- a/Robust/src/Tests/OwnershipAnalysisTest/test03/test03.java +++ b/Robust/src/Tests/OwnershipAnalysisTest/test03/test03.java @@ -21,10 +21,6 @@ public class Node { } } -// this empty task should still create a non-empty -// ownership graph showing parameter allocation -// look for the parameter s as a label referencing -// a heap region that is multi-object, flagged, not summary task Startup( StartupObject s{ initialstate } ) { Parameter1 p1 = new Parameter1(); @@ -39,12 +35,13 @@ task MakeGraph( Parameter1 p1{ !w } ) { Node n2 = Node.makeNode(); Node n3 = Node.makeNode(); + /* n1.addNeighbor( n2 ); n2.addNeighbor( n3 ); n3.addNeighbor( n1 ); p1.root = n1; - + */ taskexit( p1{ w } ); -} \ No newline at end of file +}