From c43ae9ea191cbd0d8adf3e4db5e674bee7b22a2a Mon Sep 17 00:00:00 2001 From: bdemsky Date: Mon, 29 Jun 2009 09:18:33 +0000 Subject: [PATCH] bug fixes --- .../Analysis/Locality/DelayComputation.java | 114 +++++++++++++++++- 1 file changed, 111 insertions(+), 3 deletions(-) diff --git a/Robust/src/Analysis/Locality/DelayComputation.java b/Robust/src/Analysis/Locality/DelayComputation.java index ec812588..3b4ec1e3 100644 --- a/Robust/src/Analysis/Locality/DelayComputation.java +++ b/Robust/src/Analysis/Locality/DelayComputation.java @@ -1,6 +1,7 @@ package Analysis.Locality; import Analysis.Liveness; import Analysis.ReachingDefs; +import Analysis.Loops.DomTree; import IR.State; import IR.MethodDescriptor; import IR.TypeDescriptor; @@ -428,6 +429,7 @@ public class DelayComputation { Hashtable> nodelayfieldsrd=new Hashtable>(); Hashtable> nodelayarraysrd=new Hashtable>(); + Hashtable> branchmap=getBranchSet(lb); //Effect of adding something to nodelay set is to move it up past everything in delay set //Have to make sure we can do this commute @@ -543,6 +545,14 @@ public class DelayComputation { } cannotdelay.add(fn); + if (branchmap.containsKey(fn)) { + Set fcbset=branchmap.get(fn); + for(Iterator fcbit=fcbset.iterator();fcbit.hasNext();) { + FlatCondBranch fcb=fcbit.next(); + cannotdelay.add(fcb); + nodelaytempset.add(fcb.getTest()); + } + } /* Do we write to fields */ if (fn.kind()==FKind.FlatSetFieldNode) { nodelayfieldwrset.add(((FlatSetFieldNode)fn).getField()); @@ -551,7 +561,6 @@ public class DelayComputation { if (fn.kind()==FKind.FlatFieldNode) { nodelayfieldrdset.add(((FlatFieldNode)fn).getField()); } - /* Do we write to arrays */ if (fn.kind()==FKind.FlatSetElementNode) { //have to do expansion @@ -565,6 +574,7 @@ public class DelayComputation { } else { //Need to know which objects to lock on switch(fn.kind()) { + //TODO: Can improve by only locking if there is a field that requires a lock case FKind.FlatSetFieldNode: { FlatSetFieldNode fsfn=(FlatSetFieldNode)fn; nodelaytempset.add(fsfn.getDst()); @@ -649,12 +659,14 @@ public class DelayComputation { MethodDescriptor md=lb.getMethod(); FlatMethod fm=state.getMethodFlat(md); Hashtable atomictable=locality.getAtomic(lb); - HashSet notreadynodes=new HashSet(); HashSet toanalyze=new HashSet(); toanalyze.addAll(fm.getNodeSet()); Hashtable> notreadymap=new Hashtable>(); - + + Hashtable> revbranchmap=revGetBranchSet(lb); + Hashtable> branchmap=getBranchSet(lb); + while(!toanalyze.isEmpty()) { FlatNode fn=toanalyze.iterator().next(); toanalyze.remove(fn); @@ -768,10 +780,31 @@ public class DelayComputation { } } + if (!notready) { + //See if we depend on a conditional branch that is not ready + Set branchset=branchmap.get(fn); + for(Iterator branchit=branchset.iterator();branchit.hasNext();) { + FlatCondBranch fcb=branchit.next(); + if (notreadynodes.contains(fcb)) { + //if we depend on a branch that isn't ready, we aren't ready + notready=true; + break; + } + } + } + + //Fix up things based on our status if (notready) { + if (fn.kind()==FKind.FlatCondBranch&&!notreadynodes.contains(fn)) { + //enqueue everything in our dependence set + Set branchdepset=revbranchmap.get((FlatCondBranch)fn); + toanalyze.addAll(branchdepset); + } + //add us to the list notreadynodes.add(fn); + //Add our writes TempDescriptor writeset[]=fn.writesTemps(); for(int i=0;i> revGetBranchSet(LocalityBinding lb) { + MethodDescriptor md=lb.getMethod(); + FlatMethod fm=state.getMethodFlat(md); + Hashtable> condmap=new Hashtable>(); + DomTree postdt=new DomTree(fm, true); + for(Iterator fnit=fm.getNodeSet().iterator();fnit.hasNext();) { + FlatNode fn=fnit.next(); + if (fn.kind()!=FKind.FlatCondBranch) + continue; + FlatCondBranch fcb=(FlatCondBranch)fn; + //only worry about fcb inside of transactions + if (locality.getAtomic(lb).get(fcb).intValue()==0) + continue; + FlatNode postdom=postdt.idom(fcb); + + //Reverse the mapping + Set fnset=computeBranchSet(lb, fcb, postdom); + condmap.put(fcb, fnset); + } + return condmap; + } + + public Hashtable> getBranchSet(LocalityBinding lb) { + MethodDescriptor md=lb.getMethod(); + FlatMethod fm=state.getMethodFlat(md); + Hashtable> condmap=new Hashtable>(); + DomTree postdt=new DomTree(fm, true); + for(Iterator fnit=fm.getNodeSet().iterator();fnit.hasNext();) { + FlatNode fn=fnit.next(); + if (fn.kind()!=FKind.FlatCondBranch) + continue; + FlatCondBranch fcb=(FlatCondBranch)fn; + //only worry about fcb inside of transactions + if (locality.getAtomic(lb).get(fcb).intValue()==0) + continue; + FlatNode postdom=postdt.idom(fcb); + + //Reverse the mapping + Set fnset=computeBranchSet(lb, fcb, postdom); + for(Iteratorfnit2=fnset.iterator();fnit2.hasNext();) { + FlatNode fn2=fnit2.next(); + if (!condmap.containsKey(fn2)) + condmap.put(fn2,new HashSet()); + condmap.get(fn2).add(fcb); + } + } + return condmap; + } + + public Set computeBranchSet(LocalityBinding lb, FlatNode first, FlatNode last) { + HashSet toanalyze=new HashSet(); + HashSet visited=new HashSet(); + toanalyze.add(first); + + while(!toanalyze.isEmpty()) { + FlatNode fn=toanalyze.iterator().next(); + toanalyze.remove(fn); + + //already examined or exit node + if (visited.contains(fn)||fn==last) + continue; + + //out of transaction + if (locality.getAtomic(lb).get(fn).intValue()==0) + continue; + + visited.add(fn); + for(int i=0;i