X-Git-Url: http://plrg.eecs.uci.edu/git/?p=IRC.git;a=blobdiff_plain;f=Robust%2Fsrc%2FAnalysis%2FLocality%2FDelayComputation.java;h=2d9cbe10dcade3965d836337e2436d541847881b;hp=c9c16d4e442ae1b005bdd57c74229c05d8c451f3;hb=b124b7bf09a5eed6e272119acba9cfc5a1374b60;hpb=48b17f67287ce1fe7ee09ee13ff8acd96ffd7398 diff --git a/Robust/src/Analysis/Locality/DelayComputation.java b/Robust/src/Analysis/Locality/DelayComputation.java index c9c16d4e..2d9cbe10 100644 --- a/Robust/src/Analysis/Locality/DelayComputation.java +++ b/Robust/src/Analysis/Locality/DelayComputation.java @@ -24,6 +24,7 @@ public class DelayComputation { DiscoverConflicts dcopts; Hashtable> notreadymap; Hashtable> cannotdelaymap; + Hashtable> derefmap; Hashtable> othermap; public DelayComputation(LocalityAnalysis locality, State state, TypeAnalysis typeanalysis, GlobalFieldType gft) { @@ -33,6 +34,8 @@ public class DelayComputation { this.gft=gft; this.notreadymap=new Hashtable>(); this.cannotdelaymap=new Hashtable>(); + if (state.STMARRAY&&!state.DUALVIEW) + this.derefmap=new Hashtable>(); this.othermap=new Hashtable>(); } @@ -40,49 +43,64 @@ public class DelayComputation { return dcopts; } + public Hashtable> getCannotDelayMap() { + return cannotdelaymap; + } + + + public HashSet getDeref(LocalityBinding lb) { + return derefmap.get(lb); + } + public void doAnalysis() { + //first dcopts...use to figure out what we need to lock + dcopts=new DiscoverConflicts(locality, state, typeanalysis, null); + dcopts.doAnalysis(); + + //compute cannotdelaymap Set localityset=locality.getLocalityBindings(); - for(Iterator lbit=localityset.iterator();lbit.hasNext();) { + for(Iterator lbit=localityset.iterator(); lbit.hasNext(); ) { analyzeMethod(lbit.next()); } - dcopts=new DiscoverConflicts(locality, state, typeanalysis, cannotdelaymap); + //ignore things that aren't in the map + dcopts=new DiscoverConflicts(locality, state, typeanalysis, cannotdelaymap, false, false, state.READSET?gft:null); dcopts.doAnalysis(); - for(Iterator lbit=localityset.iterator();lbit.hasNext();) { + for(Iterator lbit=localityset.iterator(); lbit.hasNext(); ) { LocalityBinding lb=lbit.next(); MethodDescriptor md=lb.getMethod(); FlatMethod fm=state.getMethodFlat(md); if (lb.isAtomic()) - continue; - + continue; + if (lb.getHasAtomic()) { - HashSet cannotdelay=cannotdelaymap.get(lb); - HashSet notreadyset=computeNotReadySet(lb, cannotdelay); - HashSet otherset=new HashSet(); - otherset.addAll(fm.getNodeSet()); - otherset.removeAll(notreadyset); - otherset.removeAll(cannotdelay); - if (state.MINIMIZE) { - Hashtable atomicmap=locality.getAtomic(lb); - for(Iterator fnit=otherset.iterator();fnit.hasNext();) { - FlatNode fn=fnit.next(); - if (atomicmap.get(fn).intValue()>0&& - fn.kind()!=FKind.FlatAtomicEnterNode&& - fn.kind()!=FKind.FlatGlobalConvNode) { - //remove non-atomic flatnodes - fnit.remove(); - notreadyset.add(fn); - } - } - } - - notreadymap.put(lb, notreadyset); - othermap.put(lb, otherset); - } - + HashSet cannotdelay=cannotdelaymap.get(lb); + HashSet notreadyset=computeNotReadySet(lb, cannotdelay); + HashSet otherset=new HashSet(); + otherset.addAll(fm.getNodeSet()); + otherset.removeAll(notreadyset); + otherset.removeAll(cannotdelay); + if (state.MINIMIZE) { + Hashtable atomicmap=locality.getAtomic(lb); + for(Iterator fnit=otherset.iterator(); fnit.hasNext(); ) { + FlatNode fn=fnit.next(); + if (atomicmap.get(fn).intValue()>0&& + fn.kind()!=FKind.FlatAtomicEnterNode&& + fn.kind()!=FKind.FlatGlobalConvNode) { + //remove non-atomic flatnodes + fnit.remove(); + notreadyset.add(fn); + } + } + } + + notreadymap.put(lb, notreadyset); + othermap.put(lb, otherset); + } + //We now have: //(1) Cannot delay set -- stuff that must be done before commit //(2) Not ready set -- stuff that must wait until commit @@ -90,6 +108,40 @@ public class DelayComputation { } } + public HashSet computeWriteSet(LocalityBinding lb) { + HashSet writeset=new HashSet(); + Set storeset=livecode(lb); + HashSet delayedset=getNotReady(lb); + Hashtable>> fnmap=dcopts.getMap(lb); + for(Iterator fnit=delayedset.iterator(); fnit.hasNext(); ) { + FlatNode fn=fnit.next(); + Hashtable> tempmap=fnmap.get(fn); + if (fn.kind()==FKind.FlatSetElementNode) { + FlatSetElementNode fsen=(FlatSetElementNode) fn; + Set tfpset=tempmap.get(fsen.getDst()); + if (tfpset!=null) { + for(Iterator tfpit=tfpset.iterator(); tfpit.hasNext(); ) { + TempFlatPair tfp=tfpit.next(); + if (storeset.contains(tfp.f)) + writeset.add(tfp.f); + } + } + } else if (fn.kind()==FKind.FlatSetFieldNode) { + FlatSetFieldNode fsfn=(FlatSetFieldNode) fn; + Set tfpset=tempmap.get(fsfn.getDst()); + if (tfpset!=null) { + for(Iterator tfpit=tfpset.iterator(); tfpit.hasNext(); ) { + TempFlatPair tfp=tfpit.next(); + if (storeset.contains(tfp.f)) + writeset.add(tfp.f); + } + } + } + } + return writeset; + } + + public HashSet getNotReady(LocalityBinding lb) { return notreadymap.get(lb); } @@ -115,19 +167,19 @@ public class DelayComputation { //make it just this transaction secondpart.retainAll(atomicnodes); - + HashSet tempset=new HashSet(); - - for(Iterator fnit=secondpart.iterator();fnit.hasNext();) { + + for(Iterator fnit=secondpart.iterator(); fnit.hasNext(); ) { FlatNode fn=fnit.next(); List writes=Arrays.asList(fn.writesTemps()); tempset.addAll(writes); if (!recordset.contains(fn)) { - List reads=Arrays.asList(fn.readsTemps()); - tempset.addAll(reads); + List reads=Arrays.asList(fn.readsTemps()); + tempset.addAll(reads); } } - + return tempset; } @@ -146,37 +198,37 @@ public class DelayComputation { secondpart.retainAll(atomicnodes); Set liveinto=new HashSet(); - - Hashtable>> reachingdefs=ReachingDefs.computeReachingDefs(fm, Liveness.computeLiveTemps(fm), true); - - for(Iterator fnit=secondpart.iterator();fnit.hasNext();) { + + Hashtable>> reachingdefs=ReachingDefs.computeReachingDefs(fm, Liveness.computeLiveTemps(fm,-1), true); + + for(Iterator fnit=secondpart.iterator(); fnit.hasNext(); ) { FlatNode fn=fnit.next(); if (recordset.contains(fn)) - continue; + continue; TempDescriptor readset[]=fn.readsTemps(); - for(int i=0;i fnset=reachingdefs.get(fn).get(rtmp); - for(Iterator fnit2=fnset.iterator();fnit2.hasNext();) { - FlatNode fn2=fnit2.next(); - if (secondpart.contains(fn2)) - continue; - //otherwise we mark this as live in - liveinto.add(rtmp); - break; - } + for(int i=0; i fnset=reachingdefs.get(fn).get(rtmp); + for(Iterator fnit2=fnset.iterator(); fnit2.hasNext(); ) { + FlatNode fn2=fnit2.next(); + if (secondpart.contains(fn2)) + continue; + //otherwise we mark this as live in + liveinto.add(rtmp); + break; + } } } return liveinto; } - //This method computes which temps are live out of the second part + //This method computes which temps are live out of the second part public Set liveoutvirtualread(LocalityBinding lb, FlatAtomicEnterNode faen) { MethodDescriptor md=lb.getMethod(); FlatMethod fm=state.getMethodFlat(md); Set exits=faen.getExits(); - Hashtable> livemap=Liveness.computeLiveTemps(fm); - Hashtable>> reachingdefs=ReachingDefs.computeReachingDefs(fm, Liveness.computeLiveTemps(fm), true); + Hashtable> livemap=Liveness.computeLiveTemps(fm,-1); + Hashtable>> reachingdefs=ReachingDefs.computeReachingDefs(fm, Liveness.computeLiveTemps(fm,-1), true); Set atomicnodes=faen.getReachableSet(faen.getExits()); @@ -186,30 +238,30 @@ public class DelayComputation { Set liveset=new HashSet(); //Have list of all live temps - for(Iterator fnit=exits.iterator();fnit.hasNext();) { + for(Iterator fnit=exits.iterator(); fnit.hasNext(); ) { FlatNode fn=fnit.next(); Set tempset=livemap.get(fn); Hashtable> reachmap=reachingdefs.get(fn); //Look for reaching defs for all live variables that are in the secondpart - for(Iterator tmpit=tempset.iterator();tmpit.hasNext();) { - TempDescriptor tmp=tmpit.next(); - Set fnset=reachmap.get(tmp); - boolean outsidenode=false; - boolean insidenode=false; - - for(Iterator fnit2=fnset.iterator();fnit2.hasNext();) { - FlatNode fn2=fnit2.next(); - if (secondpart.contains(fn2)) { - insidenode=true; - } else if (!atomicnodes.contains(fn2)) { - outsidenode=true; - } - if (outsidenode&&insidenode) { - liveset.add(tmp); - break; - } - } + for(Iterator tmpit=tempset.iterator(); tmpit.hasNext(); ) { + TempDescriptor tmp=tmpit.next(); + Set fnset=reachmap.get(tmp); + boolean outsidenode=false; + boolean insidenode=false; + + for(Iterator fnit2=fnset.iterator(); fnit2.hasNext(); ) { + FlatNode fn2=fnit2.next(); + if (secondpart.contains(fn2)) { + insidenode=true; + } else if (!atomicnodes.contains(fn2)) { + outsidenode=true; + } + if (outsidenode&&insidenode) { + liveset.add(tmp); + break; + } + } } } return liveset; @@ -220,9 +272,9 @@ public class DelayComputation { MethodDescriptor md=lb.getMethod(); FlatMethod fm=state.getMethodFlat(md); Set exits=faen.getExits(); - Hashtable> livemap=Liveness.computeLiveTemps(fm); + Hashtable> livemap=Liveness.computeLiveTemps(fm,-1); Hashtable>> reachingdefs=ReachingDefs.computeReachingDefs(fm, livemap, true); - + Set atomicnodes=faen.getReachableSet(faen.getExits()); Set secondpart=new HashSet(getNotReady(lb)); @@ -231,26 +283,26 @@ public class DelayComputation { Set liveset=new HashSet(); //Have list of all live temps - for(Iterator fnit=exits.iterator();fnit.hasNext();) { + for(Iterator fnit=exits.iterator(); fnit.hasNext(); ) { FlatNode fn=fnit.next(); Set tempset=livemap.get(fn); Hashtable> reachmap=reachingdefs.get(fn); //Look for reaching defs for all live variables that are in the secondpart - for(Iterator tmpit=tempset.iterator();tmpit.hasNext();) { - TempDescriptor tmp=tmpit.next(); - Set fnset=reachmap.get(tmp); - if (fnset==null) { - System.out.println("null temp set for"+fn+" tmp="+tmp); - System.out.println(fm.printMethod()); - } - for(Iterator fnit2=fnset.iterator();fnit2.hasNext();) { - FlatNode fn2=fnit2.next(); - if (secondpart.contains(fn2)) { - liveset.add(tmp); - break; - } - } + for(Iterator tmpit=tempset.iterator(); tmpit.hasNext(); ) { + TempDescriptor tmp=tmpit.next(); + Set fnset=reachmap.get(tmp); + if (fnset==null) { + System.out.println("null temp set for"+fn+" tmp="+tmp); + System.out.println(fm.printMethod()); + } + for(Iterator fnit2=fnset.iterator(); fnit2.hasNext(); ) { + FlatNode fn2=fnit2.next(); + if (secondpart.contains(fn2)) { + liveset.add(tmp); + break; + } + } } } return liveset; @@ -267,9 +319,12 @@ public class DelayComputation { FlatMethod fm=state.getMethodFlat(md); HashSet delayedset=notreadymap.get(lb); + HashSet derefset=null; + if (state.STMARRAY&&!state.DUALVIEW) + derefset=derefmap.get(lb); HashSet otherset=othermap.get(lb); HashSet cannotdelayset=cannotdelaymap.get(lb); - Hashtable> livemap=Liveness.computeLiveTemps(fm); + Hashtable> livemap=Liveness.computeLiveTemps(fm,-1); Hashtable>> reachingdefsmap=ReachingDefs.computeReachingDefs(fm, livemap, true); HashSet unionset=new HashSet(delayedset); Hashtable>> map=new Hashtable>>(); @@ -280,46 +335,46 @@ public class DelayComputation { //If both parts can contribute to the temp, then we need to do //reads to make sure that liveout set has the right values - for(Iterator fnit=fm.getNodeSet().iterator();fnit.hasNext();) { + for(Iterator fnit=fm.getNodeSet().iterator(); fnit.hasNext(); ) { FlatNode fn=fnit.next(); if (fn.kind()==FKind.FlatAtomicExitNode) { - Set livetemps=livemap.get(fn); - Hashtable> tempmap=reachingdefsmap.get(fn); - - //Iterate over the temps that are live into this node - for(Iterator tmpit=livetemps.iterator();tmpit.hasNext();) { - TempDescriptor tmp=tmpit.next(); - Set fnset=tempmap.get(tmp); - boolean inpart1=false; - boolean inpart2=false; - - //iterate over the reaching definitions for the temp - for(Iterator fnit2=fnset.iterator();fnit2.hasNext();) { - FlatNode fn2=fnit2.next(); - if (delayedset.contains(fn2)) { - inpart2=true; - if (inpart1) - break; - } else if (otherset.contains(fn2)||cannotdelayset.contains(fn2)) { - inpart1=true; - if (inpart2) - break; - } - } - if (inpart1&&inpart2) { - for(Iterator fnit2=fnset.iterator();fnit2.hasNext();) { - FlatNode fn2=fnit2.next(); - if ((otherset.contains(fn2)||cannotdelayset.contains(fn2))&& - locality.getAtomic(lb).get(fn2).intValue()>0) { - unionset.add(fn2); - livenodes.add(fn2); - } - } - } - } + Set livetemps=livemap.get(fn); + Hashtable> tempmap=reachingdefsmap.get(fn); + + //Iterate over the temps that are live into this node + for(Iterator tmpit=livetemps.iterator(); tmpit.hasNext(); ) { + TempDescriptor tmp=tmpit.next(); + Set fnset=tempmap.get(tmp); + boolean inpart1=false; + boolean inpart2=false; + + //iterate over the reaching definitions for the temp + for(Iterator fnit2=fnset.iterator(); fnit2.hasNext(); ) { + FlatNode fn2=fnit2.next(); + if (delayedset.contains(fn2)) { + inpart2=true; + if (inpart1) + break; + } else if (otherset.contains(fn2)||cannotdelayset.contains(fn2)) { + inpart1=true; + if (inpart2) + break; + } + } + if (inpart1&&inpart2) { + for(Iterator fnit2=fnset.iterator(); fnit2.hasNext(); ) { + FlatNode fn2=fnit2.next(); + if ((otherset.contains(fn2)||cannotdelayset.contains(fn2))&& + locality.getAtomic(lb).get(fn2).intValue()>0) { + unionset.add(fn2); + livenodes.add(fn2); + } + } + } + } } } - + HashSet toanalyze=new HashSet(); toanalyze.add(fm); @@ -330,72 +385,86 @@ public class DelayComputation { //Don't process non-atomic nodes if (locality.getAtomic(lb).get(fn).intValue()==0) { - if (!map.containsKey(fn)) { - map.put(fn, new Hashtable>()); - //enqueue next nodes - for(int i=0;i>()); + //enqueue next nodes + for(int i=0; i liveset=livemap.get(fn); //Do merge on incoming edges - for(int i=0;i> prevmap=map.get(fnprev); - if (prevmap!=null) - for(Iterator tmpit=prevmap.keySet().iterator();tmpit.hasNext();) { - TempDescriptor tmp=tmpit.next(); - if (!tmptofn.containsKey(tmp)) - tmptofn.put(tmp, new HashSet()); - tmptofn.get(tmp).addAll(prevmap.get(tmp)); - } + for(int i=0; i> prevmap=map.get(fnprev); + if (prevmap!=null) + for(Iterator tmpit=prevmap.keySet().iterator(); tmpit.hasNext(); ) { + TempDescriptor tmp=tmpit.next(); + if (!liveset.contains(tmp)) //skip dead temps + continue; + if (!tmptofn.containsKey(tmp)) + tmptofn.put(tmp, new HashSet()); + tmptofn.get(tmp).addAll(prevmap.get(tmp)); + } } if (delayedset.contains(fn)) { - //If the node is in the second set, check our readset - TempDescriptor readset[]=fn.readsTemps(); - for(int i=0;i set=new HashSet(); - tmptofn.put(tmp,set); - set.add(fn); - } - if (fn.numNext()>1) { - Set branchset=branchmap.get((FlatCondBranch)fn); - for(Iterator brit=branchset.iterator();brit.hasNext();) { - FlatNode brfn=brit.next(); - if (unionset.contains(brfn)) { - //This branch is important--need to remember how it goes - livenodes.add(fn); - unionset.add(fn); - } - } - } + //If the node is in the first set, search over what we write + //We write -- our reads are done + TempDescriptor writeset[]=fn.writesTemps(); + for(int i=0; i set=new HashSet(); + tmptofn.put(tmp,set); + set.add(fn); + } + if (fn.numNext()>1) { + Set branchset=branchmap.get((FlatCondBranch)fn); + for(Iterator brit=branchset.iterator(); brit.hasNext(); ) { + FlatNode brfn=brit.next(); + if (unionset.contains(brfn)) { + //This branch is important--need to remember how it goes + livenodes.add(fn); + unionset.add(fn); + } + } + } } if (!map.containsKey(fn)||!map.get(fn).equals(tmptofn)) { - map.put(fn, tmptofn); - //enqueue next ndoes - for(int i=0;i getNext(FlatNode fn, int i, Set delayset, LocalityBinding lb, LocalityAnalysis locality, boolean contpastnode) { Hashtable atomictable=locality.getAtomic(lb); FlatNode fnnext=fn.getNext(i); - HashSet reachable=new HashSet(); + HashSet reachable=new HashSet(); if (delayset.contains(fnnext)||atomictable.get(fnnext).intValue()==0) { reachable.add(fnnext); @@ -419,23 +488,27 @@ public class DelayComputation { while(!nodes.isEmpty()) { FlatNode fn2=nodes.pop(); if (visited.contains(fn2)) - continue; + continue; visited.add(fn2); - for (int j=0;j cannotdelay=new HashSet(); + HashSet derefset=new HashSet(); Hashtable atomictable=locality.getAtomic(lb); if (lb.isAtomic()) { //We are in a transaction already... @@ -443,6 +516,8 @@ public class DelayComputation { return; } + Hashtable> oldtempmap=dcopts.computeOldTemps(lb); + HashSet toanalyze=new HashSet(); toanalyze.addAll(fm.getNodeSet()); @@ -452,7 +527,8 @@ public class DelayComputation { Hashtable> nodelayarrayswr=new Hashtable>(); Hashtable> nodelayfieldsrd=new Hashtable>(); Hashtable> nodelayarraysrd=new Hashtable>(); - + + Hashtable> revbranchmap=revGetBranchSet(lb); 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 @@ -460,11 +536,11 @@ public class DelayComputation { while(!toanalyze.isEmpty()) { FlatNode fn=toanalyze.iterator().next(); toanalyze.remove(fn); - + boolean isatomic=atomictable.get(fn).intValue()>0; if (!isatomic) - continue; + continue; boolean isnodelay=false; /* Compute incoming nodelay sets */ @@ -473,196 +549,235 @@ public class DelayComputation { HashSet nodelayarraywrset=new HashSet(); HashSet nodelayfieldrdset=new HashSet(); HashSet nodelayarrayrdset=new HashSet(); - for(int i=0;i leftset=getNext(fn, 0, cannotdelay, lb, locality,true); - Set rightset=getNext(fn, 1, cannotdelay, lb, locality,true); - if (leftset.size()>0&&rightset.size()>0&& - !leftset.equals(rightset)||leftset.size()>1) - isnodelay=true; + Set branchset=revbranchmap.get((FlatCondBranch)fn); + for(Iterator brit=branchset.iterator(); brit.hasNext(); ) { + FlatNode branchnode=brit.next(); + if (cannotdelay.contains(branchnode)||(state.STMARRAY&&!state.DUALVIEW&&derefset.contains(branchnode))) { + isnodelay=true; + break; + } + } } //Check for field conflicts if (fn.kind()==FKind.FlatSetFieldNode) { - FieldDescriptor fd=((FlatSetFieldNode)fn).getField(); - //write conflicts - if (nodelayfieldwrset.contains(fd)) - isnodelay=true; - //read - if (nodelayfieldrdset.contains(fd)) - isnodelay=true; + FieldDescriptor fd=((FlatSetFieldNode)fn).getField(); + //write conflicts + if (nodelayfieldwrset.contains(fd)) + isnodelay=true; + //read + if (nodelayfieldrdset.contains(fd)) + isnodelay=true; } if (fn.kind()==FKind.FlatFieldNode) { - FieldDescriptor fd=((FlatFieldNode)fn).getField(); - //write conflicts - if (nodelayfieldwrset.contains(fd)) - isnodelay=true; + FieldDescriptor fd=((FlatFieldNode)fn).getField(); + //write conflicts + if (nodelayfieldwrset.contains(fd)) + isnodelay=true; } //Check for array conflicts if (fn.kind()==FKind.FlatSetElementNode) { - TypeDescriptor td=((FlatSetElementNode)fn).getDst().getType(); - //check for write conflicts - if (nodelayarraywrset.contains(td)) - isnodelay=true; - //check for read conflicts - if (nodelayarrayrdset.contains(td)) - isnodelay=true; + TypeDescriptor td=((FlatSetElementNode)fn).getDst().getType(); + //check for write conflicts + if (nodelayarraywrset.contains(td)) + isnodelay=true; + //check for read conflicts + if (nodelayarrayrdset.contains(td)) + isnodelay=true; } if (fn.kind()==FKind.FlatElementNode) { - TypeDescriptor td=((FlatElementNode)fn).getSrc().getType(); - //check for write conflicts - if (nodelayarraywrset.contains(td)) - isnodelay=true; + TypeDescriptor td=((FlatElementNode)fn).getSrc().getType(); + //check for write conflicts + if (nodelayarraywrset.contains(td)) + isnodelay=true; } - + //If we are no delay, then the temps we read are no delay if (isnodelay) { - /* Add our read set */ - TempDescriptor readset[]=fn.readsTemps(); - for(int i=0;i 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()); - } - /* Do we read from fields */ - if (fn.kind()==FKind.FlatFieldNode) { - nodelayfieldrdset.add(((FlatFieldNode)fn).getField()); - } - /* Do we write to arrays */ - if (fn.kind()==FKind.FlatSetElementNode) { - //have to do expansion - nodelayarraywrset.addAll(typeanalysis.expand(((FlatSetElementNode)fn).getDst().getType())); - } - /* Do we read from arrays */ - if (fn.kind()==FKind.FlatElementNode) { - //have to do expansion - nodelayarrayrdset.addAll(typeanalysis.expand(((FlatElementNode)fn).getSrc().getType())); - } + /* Add our read set */ + TempDescriptor readset[]=fn.readsTemps(); + for(int i=0; i fcbset=branchmap.get(fn); + for(Iterator fcbit=fcbset.iterator(); fcbit.hasNext(); ) { + FlatCondBranch fcb=fcbit.next(); + //enqueue flatcondbranch node for reanalysis + if (!cannotdelay.contains(fcb)) { + cannotdelay.add(fcb); + toanalyze.add(fcb); + } + } + } + /* Do we write to fields */ + if (fn.kind()==FKind.FlatSetFieldNode) { + nodelayfieldwrset.add(((FlatSetFieldNode)fn).getField()); + } + /* Do we read from fields */ + if (fn.kind()==FKind.FlatFieldNode) { + nodelayfieldrdset.add(((FlatFieldNode)fn).getField()); + } + /* Do we write to arrays */ + if (fn.kind()==FKind.FlatSetElementNode) { + //have to do expansion + nodelayarraywrset.addAll(typeanalysis.expand(((FlatSetElementNode)fn).getDst().getType())); + } + /* Do we read from arrays */ + if (fn.kind()==FKind.FlatElementNode) { + //have to do expansion + nodelayarrayrdset.addAll(typeanalysis.expand(((FlatElementNode)fn).getSrc().getType())); + } + + //See if flatnode is definitely no delay + if (fn.kind()==FKind.FlatCall) { + //Have to deal with fields/arrays + FlatCall fcall=(FlatCall)fn; + MethodDescriptor mdcall=fcall.getMethod(); + nodelayfieldwrset.addAll(gft.getFieldsAll(mdcall)); + nodelayarraywrset.addAll(typeanalysis.expandSet(gft.getArraysAll(mdcall))); + //Have to deal with field/array reads + nodelayfieldrdset.addAll(gft.getFieldsRdAll(mdcall)); + nodelayarrayrdset.addAll(typeanalysis.expandSet(gft.getArraysRdAll(mdcall))); + } } 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()); - break; - } - case FKind.FlatSetElementNode: { - FlatSetElementNode fsen=(FlatSetElementNode)fn; - nodelaytempset.add(fsen.getDst()); - break; - } - case FKind.FlatFieldNode: { - FlatFieldNode ffn=(FlatFieldNode)fn; - nodelaytempset.add(ffn.getSrc()); - break; - } - case FKind.FlatElementNode: { - FlatElementNode fen=(FlatElementNode)fn; - nodelaytempset.add(fen.getSrc()); - break; - } - } - } - + //Need to know which objects to lock on + Set oldtemps=oldtempmap.get(fn); + switch(fn.kind()) { + case FKind.FlatSetFieldNode: { + FlatSetFieldNode fsfn=(FlatSetFieldNode)fn; + if (oldtemps.contains(fsfn.getDst())) { + nodelaytempset.add(fsfn.getDst()); + } + break; + } + + case FKind.FlatSetElementNode: { + FlatSetElementNode fsen=(FlatSetElementNode)fn; + if (oldtemps.contains(fsen.getDst())) { + nodelaytempset.add(fsen.getDst()); + //Word Array support requires index + if (state.STMARRAY&&!state.DUALVIEW) { + nodelaytempset.add(fsen.getIndex()); + derefset.add(fsen); + } + } + break; + } + + case FKind.FlatFieldNode: { + FlatFieldNode ffn=(FlatFieldNode)fn; + if (oldtemps.contains(ffn.getSrc())&& + dcopts.getFields().contains(ffn.getField())) { + nodelaytempset.add(ffn.getSrc()); + } + break; + } + + case FKind.FlatElementNode: { + FlatElementNode fen=(FlatElementNode)fn; + if (oldtemps.contains(fen.getSrc())&& + dcopts.getArrays().contains(fen.getSrc().getType())) { + nodelaytempset.add(fen.getSrc()); + //Word Array support requires index + if (state.STMARRAY&&!state.DUALVIEW) { + nodelaytempset.add(fen.getIndex()); + derefset.add(fen); + } + } + break; + } + } + } + boolean changed=false; //See if we need to propagate changes if (!nodelaytemps.containsKey(fn)|| - !nodelaytemps.get(fn).equals(nodelaytempset)) { - nodelaytemps.put(fn, nodelaytempset); - changed=true; + !nodelaytemps.get(fn).equals(nodelaytempset)) { + nodelaytemps.put(fn, nodelaytempset); + changed=true; } //See if we need to propagate changes if (!nodelayfieldswr.containsKey(fn)|| - !nodelayfieldswr.get(fn).equals(nodelayfieldwrset)) { - nodelayfieldswr.put(fn, nodelayfieldwrset); - changed=true; + !nodelayfieldswr.get(fn).equals(nodelayfieldwrset)) { + nodelayfieldswr.put(fn, nodelayfieldwrset); + changed=true; } //See if we need to propagate changes if (!nodelayfieldsrd.containsKey(fn)|| - !nodelayfieldsrd.get(fn).equals(nodelayfieldrdset)) { - nodelayfieldsrd.put(fn, nodelayfieldrdset); - changed=true; + !nodelayfieldsrd.get(fn).equals(nodelayfieldrdset)) { + nodelayfieldsrd.put(fn, nodelayfieldrdset); + changed=true; } //See if we need to propagate changes if (!nodelayarrayswr.containsKey(fn)|| - !nodelayarrayswr.get(fn).equals(nodelayarraywrset)) { - nodelayarrayswr.put(fn, nodelayarraywrset); - changed=true; + !nodelayarrayswr.get(fn).equals(nodelayarraywrset)) { + nodelayarrayswr.put(fn, nodelayarraywrset); + changed=true; } //See if we need to propagate changes if (!nodelayarraysrd.containsKey(fn)|| - !nodelayarraysrd.get(fn).equals(nodelayarrayrdset)) { - nodelayarraysrd.put(fn, nodelayarrayrdset); - changed=true; + !nodelayarraysrd.get(fn).equals(nodelayarrayrdset)) { + nodelayarraysrd.put(fn, nodelayarrayrdset); + changed=true; } if (changed) - for(int i=0;i0; if (!isatomic) - continue; + continue; //Compute initial notready set HashSet notreadyset=new HashSet(); - for(int i=0;i tfpset=dcopts.getMap(lb).get(fn).get(tmp); - if (tfpset!=null) { - for(Iterator tfpit=tfpset.iterator();tfpit.hasNext();) { - TempFlatPair tfp=tfpit.next(); - if (!dcopts.getNeedSrcTrans(lb, tfp.f)) { - //if a source didn't need a translation and we are - //accessing it, it did...so therefore we are note - //ready - notready=true; - break; - } - } - } - break; - } - case FKind.FlatSetFieldNode: { - FlatSetFieldNode fsfn=(FlatSetFieldNode)fn; - TempDescriptor tmp=fsfn.getDst(); - Hashtable> tmpmap=dcopts.getMap(lb).get(fn); - Set tfpset=tmpmap!=null?tmpmap.get(tmp):null; - - if (tfpset!=null) { - for(Iterator tfpit=tfpset.iterator();tfpit.hasNext();) { - TempFlatPair tfp=tfpit.next(); - if (!dcopts.getNeedSrcTrans(lb, tfp.f)) { - //if a source didn't need a translation and we are - //accessing it, it did...so therefore we are note - //ready - notready=true; - break; - } - } - } - break; - } - case FKind.FlatElementNode: { - FlatElementNode fen=(FlatElementNode)fn; - if (!dcopts.getArrays().contains(fen.getSrc().getType())) { - break; - } - TempDescriptor tmp=fen.getSrc(); - Set tfpset=dcopts.getMap(lb).get(fn).get(tmp); - if (tfpset!=null) { - for(Iterator tfpit=tfpset.iterator();tfpit.hasNext();) { - TempFlatPair tfp=tfpit.next(); - if (!dcopts.getNeedSrcTrans(lb, tfp.f)) { - //if a source didn't need a translation and we are - //accessing it, it did...so therefore we are note - //ready - notready=true; - break; - } - } - } - break; - } - case FKind.FlatSetElementNode: { - FlatSetElementNode fsen=(FlatSetElementNode)fn; - TempDescriptor tmp=fsen.getDst(); - Set tfpset=dcopts.getMap(lb).get(fn).get(tmp); - if (tfpset!=null) { - for(Iterator tfpit=tfpset.iterator();tfpit.hasNext();) { - TempFlatPair tfp=tfpit.next(); - if (!dcopts.getNeedSrcTrans(lb, tfp.f)) { - //if a source didn't need a translation and we are - //accessing it, it did...so therefore we are note - //ready - notready=true; - break; - } - } - } - break; - } - } + switch(fn.kind()) { + case FKind.FlatFieldNode: { + FlatFieldNode ffn=(FlatFieldNode)fn; + if (!dcopts.getFields().contains(ffn.getField())) { + break; + } + TempDescriptor tmp=ffn.getSrc(); + Set tfpset=dcopts.getMap(lb).get(fn).get(tmp); + if (tfpset!=null) { + for(Iterator tfpit=tfpset.iterator(); tfpit.hasNext(); ) { + TempFlatPair tfp=tfpit.next(); + if (!dcopts.getNeedSrcTrans(lb, tfp.f)) { + //if a source didn't need a translation and we are + //accessing it, it did...so therefore we are note + //ready + notready=true; + break; + } + } + } + break; + } + + case FKind.FlatSetFieldNode: { + FlatSetFieldNode fsfn=(FlatSetFieldNode)fn; + TempDescriptor tmp=fsfn.getDst(); + Hashtable> tmpmap=dcopts.getMap(lb).get(fn); + Set tfpset=tmpmap!=null?tmpmap.get(tmp):null; + + if (tfpset!=null) { + for(Iterator tfpit=tfpset.iterator(); tfpit.hasNext(); ) { + TempFlatPair tfp=tfpit.next(); + if (!dcopts.getNeedSrcTrans(lb, tfp.f)) { + //if a source didn't need a translation and we are + //accessing it, it did...so therefore we are note + //ready + notready=true; + break; + } + } + } + break; + } + + case FKind.FlatElementNode: { + FlatElementNode fen=(FlatElementNode)fn; + if (!dcopts.getArrays().contains(fen.getSrc().getType())) { + break; + } + TempDescriptor tmp=fen.getSrc(); + Set tfpset=dcopts.getMap(lb).get(fn).get(tmp); + if (tfpset!=null) { + for(Iterator tfpit=tfpset.iterator(); tfpit.hasNext(); ) { + TempFlatPair tfp=tfpit.next(); + if (!dcopts.getNeedSrcTrans(lb, tfp.f)) { + //if a source didn't need a translation and we are + //accessing it, it did...so therefore we are note + //ready + notready=true; + break; + } + } + } + break; + } + + case FKind.FlatSetElementNode: { + FlatSetElementNode fsen=(FlatSetElementNode)fn; + TempDescriptor tmp=fsen.getDst(); + Set tfpset=dcopts.getMap(lb).get(fn).get(tmp); + if (tfpset!=null) { + for(Iterator tfpit=tfpset.iterator(); tfpit.hasNext(); ) { + TempFlatPair tfp=tfpit.next(); + if (!dcopts.getNeedSrcTrans(lb, tfp.f)) { + //if a source didn't need a translation and we are + //accessing it, it did...so therefore we are note + //ready + notready=true; + break; + } + } + } + break; + } + } } if (!notready) { - //See if we depend on a conditional branch that is not ready - Set branchset=branchmap.get(fn); - if (branchset!=null) - 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; - } - } + //See if we depend on a conditional branch that is not ready + Set branchset=branchmap.get(fn); + if (branchset!=null) + 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 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> condmap=new Hashtable>(); DomTree postdt=new DomTree(fm, true); - for(Iterator fnit=fm.getNodeSet().iterator();fnit.hasNext();) { + for(Iterator fnit=fm.getNodeSet().iterator(); fnit.hasNext(); ) { FlatNode fn=fnit.next(); if (fn.kind()!=FKind.FlatCondBranch) - continue; + continue; FlatCondBranch fcb=(FlatCondBranch)fn; //only worry about fcb inside of transactions if (locality.getAtomic(lb).get(fcb).intValue()==0) - continue; + continue; FlatNode postdom=postdt.idom(fcb); //Reverse the mapping @@ -882,23 +1000,23 @@ public class DelayComputation { FlatMethod fm=state.getMethodFlat(md); Hashtable> condmap=new Hashtable>(); DomTree postdt=new DomTree(fm, true); - for(Iterator fnit=fm.getNodeSet().iterator();fnit.hasNext();) { + for(Iterator fnit=fm.getNodeSet().iterator(); fnit.hasNext(); ) { FlatNode fn=fnit.next(); if (fn.kind()!=FKind.FlatCondBranch) - continue; + continue; FlatCondBranch fcb=(FlatCondBranch)fn; //only worry about fcb inside of transactions if (locality.getAtomic(lb).get(fcb).intValue()==0) - continue; + 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); + 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; @@ -915,16 +1033,16 @@ public class DelayComputation { //already examined or exit node if (visited.contains(fn)||fn==last) - continue; + continue; //out of transaction if (locality.getAtomic(lb).get(fn).intValue()==0) - continue; - - visited.add(fn); - for(int i=0;i