From 79b8407a87771ce621d1f66f3924278fb105dfe9 Mon Sep 17 00:00:00 2001 From: yeom Date: Mon, 12 Oct 2009 18:00:54 +0000 Subject: [PATCH] collects live-in var's allocation sites when it references to parameter heap region. --- Robust/src/Analysis/MLP/MLPAnalysis.java | 156 +++++++++++++++++++++-- 1 file changed, 147 insertions(+), 9 deletions(-) diff --git a/Robust/src/Analysis/MLP/MLPAnalysis.java b/Robust/src/Analysis/MLP/MLPAnalysis.java index fdb44dc8..e646ec6b 100644 --- a/Robust/src/Analysis/MLP/MLPAnalysis.java +++ b/Robust/src/Analysis/MLP/MLPAnalysis.java @@ -190,17 +190,18 @@ public class MLPAnalysis { // new pass methItr = ownAnalysis.descriptorsToAnalyze.iterator(); + JavaCallGraph javaCallGraph = new JavaCallGraph(state,tu); while( methItr.hasNext() ) { Descriptor d = methItr.next(); FlatMethod fm = state.getMethodFlat( d ); - methodEffects(fm); + methodEffects(fm,javaCallGraph); } // disjoint analysis with a set of flagged allocation sites of live-in variable try { OwnershipAnalysis oa2 = new OwnershipAnalysis(state, tu, callGraph, - state.OWNERSHIPALLOCDEPTH, state.OWNERSHIPWRITEDOTS, - state.OWNERSHIPWRITEALL, state.OWNERSHIPALIASFILE, + state.OWNERSHIPALLOCDEPTH, false, + false, state.OWNERSHIPALIASFILE, state.METHODEFFECTS, mapMethodContextToLiveInAllocationSiteSet); // debug @@ -815,7 +816,7 @@ public class MLPAnalysis { private void debugFunction(OwnershipAnalysis oa2, FlatMethod fm) { - String methodName="method1"; + String methodName="doSomeWork"; MethodDescriptor md=fm.getMethod(); HashSet mcSet=oa2.getAllMethodContextSetByDescriptor(md); @@ -825,7 +826,6 @@ public class MLPAnalysis { MethodContext mc=mcIter.next(); OwnershipGraph og=oa2.getOwnvershipGraphByMethodContext(mc); -// System.out.println("FM="+fm.toString()); if(fm.toString().indexOf(methodName)>0){ try { @@ -842,7 +842,7 @@ public class MLPAnalysis { } - private void methodEffects(FlatMethod fm) { + private void methodEffects(FlatMethod fm, CallGraph callGraph) { MethodDescriptor md=fm.getMethod(); HashSet mcSet=ownAnalysis.getAllMethodContextSetByDescriptor(md); @@ -864,7 +864,7 @@ public class MLPAnalysis { assert seseStack != null; if (!seseStack.empty()) { - effects_nodeActions(mc, fn, seseStack.peek()); + effects_nodeActions(mc, fn, seseStack.peek(), callGraph); } flatNodesToVisit.remove(fn); @@ -883,9 +883,143 @@ public class MLPAnalysis { } } + + private void analyzeRelatedAllocationSite(MethodDescriptor callerMD, + MethodContext calleeMC, HashSet paramIndexSet) { + + HashSet mcSet = ownAnalysis + .getAllMethodContextSetByDescriptor(callerMD); + Iterator mcIter = mcSet.iterator(); + + FlatMethod callerFM = state.getMethodFlat(callerMD); + + while (mcIter.hasNext()) { + MethodContext mc = mcIter.next(); + + Set visited = new HashSet(); + Set flatNodesToVisit = new HashSet(); + flatNodesToVisit.add(callerFM); + + while (!flatNodesToVisit.isEmpty()) { + FlatNode fn = (FlatNode) flatNodesToVisit.iterator().next(); + flatNodesToVisit.remove(fn); + + analyzeRelatedAllocationSite_NodeAction(fn, mc, calleeMC, paramIndexSet); + + flatNodesToVisit.remove(fn); + visited.add(fn); + + for (int i = 0; i < fn.numNext(); i++) { + FlatNode nn = fn.getNext(i); + if (!visited.contains(nn)) { + flatNodesToVisit.add(nn); + } + } + } + + } + + } + + private void analyzeRelatedAllocationSite_NodeAction(FlatNode fn, MethodContext callerMC, + MethodContext calleeMC, HashSet paramIndexSet) { + + OwnershipGraph og = ownAnalysis + .getOwnvershipGraphByMethodContext(callerMC); + + switch (fn.kind()) { + + case FKind.FlatCall: { + + FlatCall fc = (FlatCall) fn; + + MethodContext calleeMCfromOG = ownAnalysis.getCalleeMethodContext( + callerMC, fc); + + if (calleeMC.equals(calleeMCfromOG)) { + // in this case, this method context calls corresponding callee. + int base; + if (((MethodDescriptor) calleeMC.getDescriptor()).isStatic()) { + base = 0; + } else { + base = 1; + } + + for (Iterator iterator = paramIndexSet.iterator(); iterator + .hasNext();) { + Integer integer = (Integer) iterator.next(); + + int paramIdx=integer-base; + if(paramIdx>=0){ + // if paramIdx is less than 0, assumes that it is related with wrong method contexts. + TempDescriptor arg = fc.getArg(paramIdx ); + LabelNode argLN = og.td2ln.get(arg); + if (argLN != null) { + Iterator iterEdge = argLN + .iteratorToReferencees(); + while (iterEdge.hasNext()) { + ReferenceEdge referenceEdge = (ReferenceEdge) iterEdge + .next(); + + HeapRegionNode dstHRN=referenceEdge.getDst(); + if(dstHRN.isParameter()){ + setupRelatedAllocSiteAnalysis(og,callerMC,dstHRN); + }else{ + addLiveInAllocationSite(callerMC, dstHRN + .getAllocationSite()); + } + } + } + } + } + } + + } + break; + + } + } + + private void setupRelatedAllocSiteAnalysis(OwnershipGraph og, + MethodContext mc, HeapRegionNode dstHRN) { + + HashSet paramIndexSet = new HashSet(); + + // collect corresponding param index + Set pIndexSet = og.idPrimary2paramIndexSet.get(dstHRN.getID()); + if (pIndexSet != null) { + for (Iterator iterator = pIndexSet.iterator(); iterator.hasNext();) { + Integer integer = (Integer) iterator.next(); + paramIndexSet.add(integer); + } + } + + Set sIndexSet = og.idSecondary2paramIndexSet.get(dstHRN + .getID()); + if (sIndexSet != null) { + for (Iterator iterator = sIndexSet.iterator(); iterator.hasNext();) { + Integer integer = (Integer) iterator.next(); + paramIndexSet.add(integer); + } + } + + if (mc.getDescriptor() instanceof MethodDescriptor) { + Set callerSet = callGraph.getCallerSet((MethodDescriptor) mc + .getDescriptor()); + for (Iterator iterator = callerSet.iterator(); iterator.hasNext();) { + Object obj = (Object) iterator.next(); + if (obj instanceof MethodDescriptor) { + MethodDescriptor callerMD = (MethodDescriptor) obj; + + analyzeRelatedAllocationSite(callerMD, mc, paramIndexSet); + + } + } + } + } private void effects_nodeActions(MethodContext mc, FlatNode fn, - FlatSESEEnterNode currentSESE) { + FlatSESEEnterNode currentSESE, CallGraph callGraph) { OwnershipGraph og = ownAnalysis.getOwnvershipGraphByMethodContext(mc); @@ -914,7 +1048,11 @@ public class MLPAnalysis { ReferenceEdge referenceEdge = (ReferenceEdge) referenceeIter .next(); HeapRegionNode dstHRN = referenceEdge.getDst(); - if (!dstHRN.isParameter()) { + if (dstHRN.isParameter()) { + + setupRelatedAllocSiteAnalysis(og,mc,dstHRN); + + } else { addLiveInAllocationSite(mc, dstHRN .getAllocationSite()); } -- 2.34.1