From 9dd40d449639bdc765eab0aa10c8abbe68a00d40 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Mon, 13 Apr 2009 04:55:22 +0000 Subject: [PATCH] changes --- .../Analysis/Locality/DiscoverConflicts.java | 580 +++++++++--------- Robust/src/Main/Main.java | 2 + 2 files changed, 299 insertions(+), 283 deletions(-) diff --git a/Robust/src/Analysis/Locality/DiscoverConflicts.java b/Robust/src/Analysis/Locality/DiscoverConflicts.java index 36da9d6b..b3444de6 100644 --- a/Robust/src/Analysis/Locality/DiscoverConflicts.java +++ b/Robust/src/Analysis/Locality/DiscoverConflicts.java @@ -7,22 +7,21 @@ import java.util.HashSet; import java.util.Iterator; import java.util.Hashtable; import IR.State; +import IR.Operation; import IR.TypeDescriptor; import IR.MethodDescriptor; import IR.FieldDescriptor; -public DiscoverConflicts { +public class DiscoverConflicts { Set fields; Set arrays; LocalityAnalysis locality; State state; - Hashtable> needsTR; public DiscoverConflicts(LocalityAnalysis locality, State state) { this.locality=locality; this.fields=new HashSet(); this.arrays=new HashSet(); - this.needsTR=new Hashtable>(); this.state=state; transreadmap=new Hashtable>(); srcmap=new Hashtable>(); @@ -31,31 +30,30 @@ public DiscoverConflicts { public void doAnalysis() { //Compute fields and arrays for all transactions Set localityset=locality.getLocalityBindings(); - for(Iterator lb=localityset.iteratory();lb.hasNext();) { + for(Iterator lb=localityset.iterator();lb.hasNext();) { computeModified(lb.next()); } expandTypes(); //Compute set of nodes that need transread - Set localityset=locality.getLocalityBindings(); - for(Iterator lb=localityset.iteratory();lb.hasNext();) { + for(Iterator lb=localityset.iterator();lb.hasNext();) { analyzeLocality(lb.next()); } } public void expandTypes() { - FIX ARRAY...compute super/sub sets of each so we can do simple membership test + //FIX ARRAY...compute super/sub sets of each so we can do simple membership test } - Hashtable> doMerge(FlatNode fn, Hashtable>> tmptofnset) { - Hashtable> table=new Hashtable>(); + Hashtable> doMerge(FlatNode fn, Hashtable>> tmptofnset) { + Hashtable> table=new Hashtable>(); for(int i=0;i> tabset=tmptofnset.get(fprev); + Hashtable> tabset=tmptofnset.get(fprev); if (tabset!=null) { for(Iterator tmpit=tabset.keySet().iterator();tmpit.hasNext();) { TempDescriptor td=tmpit.next(); - Set fnset=tabset.get(td); + Set fnset=tabset.get(td); if (!table.containsKey(td)) - table.put(td, new HashSet()); + table.put(td, new HashSet()); table.get(td).addAll(fnset); } } @@ -66,296 +64,312 @@ public DiscoverConflicts { Hashtable> transreadmap; Hashtable> srcmap; + public Set getNeedSrcTrans(LocalityBinding lb) { + return srcmap.get(lb); + } - public void analyzeLocality(LocalityBinding lb) { - Hashtable>> fnmap=computeTempSets(lb); - HashSet tfset=computeTranslationSet(lb, fnmap); - HashSet srctrans=new HashSet(); - transreadmap.put(lb, tfset); - srcmap.put(lb,srctrans); + public Set getNeedReadTrans(LocalityBinding lb) { + HashSet set=new HashSet(); + for(Iterator it=transreadmap.get(lb).iterator();it.hasNext();) { + TempFlatPair tfp=it.next(); + set.add(tfp.f); + } + return set; + } - for(Iterator fnit=fm.getNodeSet().iterator();fnit.hasNext();) { - FlatNode fn=fnit.next(); - Hashtable atomictable=locality.getAtomic(lb); - if (atomictable.get(fn).intValue()>0) { - Hashtable> tmap=fnmap.get(fn); - switch(fn.kind()) { - case FKind.FlatSetFieldNode: { - //definitely need to translate these - FlatSetFieldNode fsfn=(FlatSetFieldNode)fn; - Set tfpset=tmap.get(fsfn.getSrc()); - for(Iterator tfpit=tfpset.iterator();tfpit.hasNext();) { - TempFlatPair tfp=tfpit.nexT(); - if (tfset.contains(tfp)) { - srctrans.add(fsfn); - break; - } - } - break; - } - case FKind.FlatSetElementNode: { - //definitely need to translate these - FlatSetElementNode fsen=(FlatSetElementNode)fn; - Set tfpset=tmap.get(fsen.getSrc()); - for(Iterator tfpit=tfpset.iterator();tfpit.hasNext();) { - TempFlatPair tfp=tfpit.nexT(); - if (tfset.contains(tfp)) { - srctrans.add(fsfn); - break; - } - } - break; - } - default: - } + + private void analyzeLocality(LocalityBinding lb) { + MethodDescriptor md=lb.getMethod(); + FlatMethod fm=state.getMethodFlat(md); + Hashtable>> fnmap=computeTempSets(lb); + HashSet tfset=computeTranslationSet(lb, fm, fnmap); + HashSet srctrans=new HashSet(); + transreadmap.put(lb, tfset); + srcmap.put(lb,srctrans); + + for(Iterator fnit=fm.getNodeSet().iterator();fnit.hasNext();) { + FlatNode fn=fnit.next(); + Hashtable atomictable=locality.getAtomic(lb); + if (atomictable.get(fn).intValue()>0) { + Hashtable> tmap=fnmap.get(fn); + switch(fn.kind()) { + case FKind.FlatSetFieldNode: { + //definitely need to translate these + FlatSetFieldNode fsfn=(FlatSetFieldNode)fn; + Set tfpset=tmap.get(fsfn.getSrc()); + for(Iterator tfpit=tfpset.iterator();tfpit.hasNext();) { + TempFlatPair tfp=tfpit.next(); + if (tfset.contains(tfp)) { + srctrans.add(fsfn); + break; + } + } + break; + } + case FKind.FlatSetElementNode: { + //definitely need to translate these + FlatSetElementNode fsen=(FlatSetElementNode)fn; + Set tfpset=tmap.get(fsen.getSrc()); + for(Iterator tfpit=tfpset.iterator();tfpit.hasNext();) { + TempFlatPair tfp=tfpit.next(); + if (tfset.contains(tfp)) { + srctrans.add(fsen); + break; } + } + break; + } + default: } + } } + } - HashSet computeTranslationSet(LocalityBinding lb, Hashtable>> fnmap) { - HashSet tfset=new HashSet(); + HashSet computeTranslationSet(LocalityBinding lb, FlatMethod fm, Hashtable>> fnmap) { + HashSet tfset=new HashSet(); + + for(Iterator fnit=fm.getNodeSet().iterator();fnit.hasNext();) { + FlatNode fn=fnit.next(); + Hashtable atomictable=locality.getAtomic(lb); + if (atomictable.get(fn).intValue()>0) { + Hashtable> tmap=fnmap.get(fn); + switch(fn.kind()) { + case FKind.FlatElementNode: { + FlatElementNode fen=(FlatElementNode)fn; + if (arrays.contains(fen.getSrc().getType())) { + //this could cause conflict...figure out conflict set + Set tfpset=tmap.get(fen.getSrc()); + tfset.addAll(tfpset); + } + break; + } + case FKind.FlatFieldNode: { + FlatFieldNode ffn=(FlatFieldNode)fn; + if (fields.contains(ffn.getField())) { + //this could cause conflict...figure out conflict set + Set tfpset=tmap.get(ffn.getSrc()); + tfset.addAll(tfpset); + } + break; + } + case FKind.FlatSetFieldNode: { + //definitely need to translate these + FlatSetFieldNode fsfn=(FlatSetFieldNode)fn; + Set tfpset=tmap.get(fsfn.getDst()); + tfset.addAll(tfpset); + break; + } + case FKind.FlatSetElementNode: { + //definitely need to translate these + FlatSetElementNode fsen=(FlatSetElementNode)fn; + Set tfpset=tmap.get(fsen.getDst()); + tfset.addAll(tfpset); + break; + } + case FKind.FlatCall: //assume pessimistically that calls do bad things + case FKind.FlatReturnNode: { + TempDescriptor []readarray=fn.readsTemps(); + for(int i=0;i tfpset=tmap.get(rtmp); + tfset.addAll(tfpset); + } + break; + } + default: + //do nothing + } + } + } + return tfset; + } - for(Iterator fnit=fm.getNodeSet().iterator();fnit.hasNext();) { - FlatNode fn=fnit.next(); - Hashtable atomictable=locality.getAtomic(lb); - if (atomictable.get(fn).intValue()>0) { - Hashtable> tmap=fnmap.get(fn); - switch(fn.kind()) { - case FKind.FlatElementNode: { - FlatElementNode fen=(FlatElementNode)fn; - if (arrays.contains(fen.getField())) { - //this could cause conflict...figure out conflict set - Set tfpset=tmap.get(fen.getSrc()); - tfset.addAll(tfpset); - } - break; - } - case FKind.FlatFieldNode: { - FlatFieldNode ffn=(FlatFieldNode)fn; - if (fields.contains(ffn.getField())) { - //this could cause conflict...figure out conflict set - Set tfpset=tmap.get(ffn.getSrc()); - tfset.addAll(tfpset); - } - break; - } - case FKind.FlatSetFieldNode: { - //definitely need to translate these - FlatSetFieldNode fsfn=(FlatSetFieldNode)fn; - Set tfpset=tmap.get(fsfn.getDst()); - tfset.addAll(tfpset); - break; - } - case FKind.FlatSetElementNode: { - //definitely need to translate these - FlatSetElementNode fsen=(FlatSetElementNode)fn; - Set tfpset=tmap.get(fsen.getDst()); - tfset.addAll(tfpset); - break; - } - case FKind.FlatCall: //assume pessimistically that calls do bad things - case FKind.FlatReturn: { - TempDescriptor []readarray=fn.readsTemps(); - for(int i=0;i tfpset=tmap.get(rtmp); - tfset.addAll(tfpset); - } - break; - default: - //do nothing - } - } + Hashtable>> computeTempSets(LocalityBinding lb) { + Hashtable>> tmptofnset=new Hashtable>>(); + HashSet discovered=new HashSet(); + HashSet tovisit=new HashSet(); + MethodDescriptor md=lb.getMethod(); + FlatMethod fm=state.getMethodFlat(md); + Hashtable atomictable=locality.getAtomic(lb); + Hashtable> livetemps=locality.computeLiveTemps(fm); + tovisit.add(fm); + discovered.add(fm); + + while(!tovisit.isEmpty()) { + FlatNode fn=tovisit.iterator().next(); + tovisit.remove(fn); + for(int i=0;i> ttofn=null; + if (atomictable.get(fn).intValue()!=0) { + if ((fn.numPrev()>0)&&atomictable.get(fn.getPrev(0)).intValue()==0) { + //flatatomic enter node... see what we really need to transread + Set liveset=livetemps.get(fn); + ttofn=new Hashtable>(); + for(Iterator tmpit=liveset.iterator();tmpit.hasNext();) { + TempDescriptor tmp=tmpit.next(); + if (tmp.getType().isPtr()) { + HashSet fnset=new HashSet(); + fnset.add(new TempFlatPair(tmp, fn)); + ttofn.put(tmp, fnset); } - } - return tfset; - } - - Hashtable>> computeTempSets(LocalityBinding lb) { - Hashtable> tmptofnset=new Hashtable, Set>(); - HashSet discovered=new HashSet(); - HashSet tovisit=new HashSet(); - MethodDescriptor md=lb.getMethod(); - FlatMethod fm=state.getMethodFlat(md); - Hashtable atomictable=locality.getAtomic(lb); - Hashtable> livetemps=locality.computeLiveTemps(fm); - tovisit.add(fm); - discovered.add(fm); - - while(!tovisit.isEmpty()) { - FlatNode fn=tovisit.iterator().next(); - tovisit.remove(fn); - for(int i=0;i set=new HashSet(); + set.add(new TempFlatPair(wtmp, fn)); + ttofn.put(wtmp, set); } - Hashtable> ttofn=null; - if (atomictable.get(fn).intValue()!=0) { - if (fn.numPrev()>0&&atomictable.get(fn.getPrev(0))) { - //flatatomic enter node... see what we really need to transread - Set liveset=livetemps.get(fn); - ttofn=new Hashtable>(); - for(Iterator tmpit=liveset.iterator();tmpit.hasNext();) { - TempDescriptor tmp=tmpit.next(); - if (tmp.getType().isPtr()) { - HashSet fnset=new HashSet(); - fnset.add(new TempFlatPair(tmp, fn)); - ttofn.put(tmp, fnset); - } - } - } else { - ttofn=doMerge(fn, tmptofnset); - switch(fn.kind()) { - case FKind.FlatFieldNode: - case FKind.FlatElementNode: { - TempDescriptor[] writes=fn.writesTemps(); - for(int i=0;i set=new HashSet(); - set.add(new TempFlatPair(wtmp, fn)); - mtable.put(wtmp, set); - } - break; - } - case FKind.FlatOpNode: { - FlatOpNode fon=(FlatOpNode)fn; - if (fon.getOp().getOp()==Operation.ASSIGN&&fon.getDest().getType().isPtr()) { - mtable.put(fon.getDest(), new HashSet(mtable.get(fon.getLeft()))); - break; - } - } - default: - //Do kill computation - TempDescriptor[] writes=fn.writesTemps(); - for(int i=0;i(ttofn.get(fon.getLeft()))); + break; } - } - return tmptofnset; - } - - public void computeModified(LocalityBinding lb) { - Hashtable> oldtemps=computeOldTemps(lb); - for(Iterator fnit=fm.getNodeSet().iterator();fnit.hasNext();) { - FlatNode fn=fnit.next(); - Hashtable atomictable=locality.getAtomic(lb); - if (atomictable.get(fn).intValue()>0) { - switch (fn.kind()) { - case FKind.FlatSetFieldNode: - FlatSetFieldNode fsfn=(FlatSetFieldNode) fn; - fields.add(fsfn.getField()); - break; - case FKind.FlatSetElementNode: - FlatSetElementNode fsfn=(FlatSetElementNode) fn; - arrays.add(fsen.getDst().getType()); - break; - default: - } + } + default: + //Do kill computation + TempDescriptor[] writes=fn.writesTemps(); + for(int i=0;i> oldtemps=computeOldTemps(lb); + for(Iterator fnit=fm.getNodeSet().iterator();fnit.hasNext();) { + FlatNode fn=fnit.next(); + Hashtable atomictable=locality.getAtomic(lb); + if (atomictable.get(fn).intValue()>0) { + switch (fn.kind()) { + case FKind.FlatSetFieldNode: + FlatSetFieldNode fsfn=(FlatSetFieldNode) fn; + fields.add(fsfn.getField()); + break; + case FKind.FlatSetElementNode: + FlatSetElementNode fsen=(FlatSetElementNode) fn; + arrays.add(fsen.getDst().getType()); + break; + default: + } + } } + } - Hashtable> computeOldTemps(LocalityBinding lb) { - Hashtable> fntooldtmp=new Hashtable>(); - HashSet discovered=new HashSet(); - HashSet tovisit=new HashSet(); - MethodDescriptor md=lb.getMethod(); - FlatMethod fm=state.getMethodFlat(md); - Hashtable atomictable=locality.getAtomic(lb); - Hashtable> livetemps=locality.computeLiveTemps(fm); - tovisit.add(fm); - discovered.add(fm); - - while(!tovisit.isEmpty()) { - FlatNode fn=tovisit.iterator().next(); - tovisit.remove(fn); - for(int i=0;i> computeOldTemps(LocalityBinding lb) { + Hashtable> fntooldtmp=new Hashtable>(); + HashSet discovered=new HashSet(); + HashSet tovisit=new HashSet(); + MethodDescriptor md=lb.getMethod(); + FlatMethod fm=state.getMethodFlat(md); + Hashtable atomictable=locality.getAtomic(lb); + Hashtable> livetemps=locality.computeLiveTemps(fm); + tovisit.add(fm); + discovered.add(fm); + + while(!tovisit.isEmpty()) { + FlatNode fn=tovisit.iterator().next(); + tovisit.remove(fn); + for(int i=0;i oldtemps=null; + if (atomictable.get(fn).intValue()!=0) { + if ((fn.numPrev()>0)&&atomictable.get(fn.getPrev(0)).intValue()==0) { + //Everything live is old + Set lives=livetemps.get(fn); + oldtemps=new HashSet(); + + for(Iterator it=lives.iterator();it.hasNext();) { + TempDescriptor tmp=it.next(); + if (tmp.getType().isPtr()) { + oldtemps.add(tmp); } - HashSet oldtemps=null; - if (atomictable.get(fn).intValue()!=0) { - if (fn.numPrev()>0&&atomictable.get(fn.getPrev(0))) { - //Everything live is old - Set lives=livetemps.get(fn); - oldtemps=new HashSet(); - - for(Iterator it=lives.iterator();it.hasNext();) { - TempDescriptor tmp=it.next(); - if (tmp.getType().isPtr()) { - oldtemps.add(tmp); - } - } else { - oldtemps=new HashSet(); - //Compute union of old temporaries - for(int i=0;i pset=fnotooldtmp.get(fn.getPrev(i)); - if (pset!=null) - oldtemps.addAll(pset); - } - - switch (fn.kind()) { - case FKind.FlatNew: - oldtemps.removeAll(Arrays.asList(fn.readsTemps())); - break; - case FKind.FlatOpNode: - { - FlatOpNode fon=(FlatOpNode)fn; - if (fon.getOp().getOp()==Operation.ASSIGN&&fn.getDest().getType().isPtr()) { - if (oldtemps.contains(fn.getLeft())) - oldtemps.add(fn.getDest()); - else - oldtemps.remove(fn.getDest()); - break; - } - } - default: - { - TempDescriptor[] writes=fn.writesTemps(); - for(int i=0;i(); + //Compute union of old temporaries + for(int i=0;i pset=fntooldtmp.get(fn.getPrev(i)); + if (pset!=null) + oldtemps.addAll(pset); + } + + switch (fn.kind()) { + case FKind.FlatNew: + oldtemps.removeAll(Arrays.asList(fn.readsTemps())); + break; + case FKind.FlatOpNode: { + FlatOpNode fon=(FlatOpNode)fn; + if (fon.getOp().getOp()==Operation.ASSIGN&&fon.getDest().getType().isPtr()) { + if (oldtemps.contains(fon.getLeft())) + oldtemps.add(fon.getDest()); + else + oldtemps.remove(fon.getDest()); + break; } - if (oldtemps!=null) { - if (!fntooldtmp.containsKey(fn)||!fntooldtmp.get(fn).equals(oldtemps)) { - fntooldtmp.put(fn, oldtemps); - //propagate changes - for(int i=0;i