From e371cde59b166dabc05e2ec5c0889ffaefa0ae14 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Mon, 13 Jul 2009 00:35:22 +0000 Subject: [PATCH] changes to get last benchmark working well --- .../Analysis/Locality/DelayComputation.java | 2 +- .../Analysis/Locality/DiscoverConflicts.java | 153 +++++++++++++++++- Robust/src/IR/Flat/BuildCode.java | 30 ++-- Robust/src/IR/State.java | 1 + Robust/src/IR/TypeDescriptor.java | 2 +- Robust/src/buildscript | 17 ++ 6 files changed, 187 insertions(+), 18 deletions(-) diff --git a/Robust/src/Analysis/Locality/DelayComputation.java b/Robust/src/Analysis/Locality/DelayComputation.java index b7c48bbf..011938a1 100644 --- a/Robust/src/Analysis/Locality/DelayComputation.java +++ b/Robust/src/Analysis/Locality/DelayComputation.java @@ -51,7 +51,7 @@ public class DelayComputation { } //ignore things that aren't in the map - dcopts=new DiscoverConflicts(locality, state, typeanalysis, cannotdelaymap, false, false); + dcopts=new DiscoverConflicts(locality, state, typeanalysis, cannotdelaymap, false, false, state.READSET?gft:null); dcopts.doAnalysis(); diff --git a/Robust/src/Analysis/Locality/DiscoverConflicts.java b/Robust/src/Analysis/Locality/DiscoverConflicts.java index 6dfc4a27..11c4cb35 100644 --- a/Robust/src/Analysis/Locality/DiscoverConflicts.java +++ b/Robust/src/Analysis/Locality/DiscoverConflicts.java @@ -12,6 +12,7 @@ import IR.TypeDescriptor; import IR.MethodDescriptor; import IR.FieldDescriptor; import Analysis.Liveness; +import Analysis.Loops.GlobalFieldType; public class DiscoverConflicts { Set fields; @@ -20,6 +21,8 @@ public class DiscoverConflicts { State state; Hashtable> treadmap; Hashtable> transreadmap; + Hashtable> twritemap; + Hashtable> writemap; Hashtable> srcmap; Hashtable> leftsrcmap; Hashtable> rightsrcmap; @@ -28,8 +31,9 @@ public class DiscoverConflicts { Hashtable>>> lbtofnmap; boolean inclusive=false; boolean normalassign=false; + GlobalFieldType gft; - public DiscoverConflicts(LocalityAnalysis locality, State state, TypeAnalysis typeanalysis) { + public DiscoverConflicts(LocalityAnalysis locality, State state, TypeAnalysis typeanalysis, GlobalFieldType gft) { this.locality=locality; this.fields=new HashSet(); this.arrays=new HashSet(); @@ -41,9 +45,14 @@ public class DiscoverConflicts { leftsrcmap=new Hashtable>(); rightsrcmap=new Hashtable>(); lbtofnmap=new Hashtable>>>(); + if (gft!=null) { + twritemap=new Hashtable>(); + writemap=new Hashtable>(); + } + this.gft=gft; } - public DiscoverConflicts(LocalityAnalysis locality, State state, TypeAnalysis typeanalysis, Hashtable> cannotdelaymap, boolean inclusive, boolean normalassign) { + public DiscoverConflicts(LocalityAnalysis locality, State state, TypeAnalysis typeanalysis, Hashtable> cannotdelaymap, boolean inclusive, boolean normalassign, GlobalFieldType gft) { this.locality=locality; this.fields=new HashSet(); this.arrays=new HashSet(); @@ -58,6 +67,11 @@ public class DiscoverConflicts { lbtofnmap=new Hashtable>>>(); this.inclusive=inclusive; this.normalassign=normalassign; + if (gft!=null) { + twritemap=new Hashtable>(); + writemap=new Hashtable>(); + } + this.gft=gft; } public Set getFields() { @@ -94,6 +108,15 @@ public class DiscoverConflicts { set.add(tfp.f); } treadmap.put(lb, set); + if (gft!=null) { + //need to translate write map set + set=new HashSet(); + for(Iterator it=writemap.get(lb).iterator();it.hasNext();) { + TempFlatPair tfp=it.next(); + set.add(tfp.f); + } + twritemap.put(lb, set); + } } //We have a set of things we write to, figure out what things this @@ -145,6 +168,10 @@ public class DiscoverConflicts { return treadmap.get(lb).contains(fn); } + public boolean getNeedWriteTrans(LocalityBinding lb, FlatNode fn) { + return twritemap.get(lb).contains(fn); + } + public Hashtable>> getMap(LocalityBinding lb) { return lbtofnmap.get(lb); } @@ -152,9 +179,19 @@ public class DiscoverConflicts { private void analyzeLocality(LocalityBinding lb) { MethodDescriptor md=lb.getMethod(); FlatMethod fm=state.getMethodFlat(md); + + //Compute map from flatnode -> (temps -> source of value) Hashtable>> fnmap=computeTempSets(lb); lbtofnmap.put(lb,fnmap); - HashSet tfset=computeTranslationSet(lb, fm, fnmap); + HashSet writeset=null; + if (gft!=null) { + writeset=new HashSet(); + } + HashSet tfset=computeTranslationSet(lb, fm, fnmap, writeset); + if (gft!=null) { + writemap.put(lb, writeset); + } + HashSet srctrans=new HashSet(); HashSet leftsrctrans=new HashSet(); HashSet rightsrctrans=new HashSet(); @@ -164,7 +201,6 @@ public class DiscoverConflicts { rightsrcmap.put(lb,rightsrctrans); //compute writes that need translation on source - for(Iterator fnit=fm.getNodeSet().iterator();fnit.hasNext();) { FlatNode fn=fnit.next(); Hashtable atomictable=locality.getAtomic(lb); @@ -284,6 +320,76 @@ public class DiscoverConflicts { return fn.kind()==FKind.FlatCall||fn.kind()==FKind.FlatMethod; } + private void computeReadOnly(LocalityBinding lb, Hashtable> updatedtypemap, Hashtable> updatedfieldmap) { + //inside of transaction, try to convert rw access to ro access + MethodDescriptor md=lb.getMethod(); + FlatMethod fm=state.getMethodFlat(md); + Hashtable atomictable=locality.getAtomic(lb); + + HashSet toanalyze=new HashSet(); + toanalyze.addAll(fm.getNodeSet()); + + while(!toanalyze.isEmpty()) { + FlatNode fn=toanalyze.iterator().next(); + toanalyze.remove(fn); + HashSet updatetypeset=new HashSet(); + HashSet updatefieldset=new HashSet(); + + //Stop if we aren't in a transaction + if (atomictable.get(fn).intValue()==0) + continue; + + //Do merge of all exits + for(int i=0;i fields=gft.getFieldsAll(mdfc); + updatefieldset.addAll(fields); + + //get modified arrays + Set arrays=gft.getArraysAll(mdfc); + updatetypeset.addAll(typeanalysis.expandSet(arrays)); + break; + } + } + } + + if (!updatedtypemap.containsKey(fn)||!updatedfieldmap.containsKey(fn)|| + !updatedtypemap.get(fn).equals(updatetypeset)||!updatedfieldmap.get(fn).equals(updatefieldset)) { + updatedtypemap.put(fn, updatetypeset); + updatedfieldmap.put(fn, updatefieldset); + for(int i=0;i computeTranslationSet(LocalityBinding lb, FlatMethod fm, Hashtable>> fnmap) { + + HashSet computeTranslationSet(LocalityBinding lb, FlatMethod fm, Hashtable>> fnmap, Set writeset) { HashSet tfset=new HashSet(); + //Compute maps from flatnodes -> sets of things that may be updated after this node + Hashtable> updatedtypemap=null; + Hashtable> updatedfieldmap=null; + + if (writeset!=null&&!lb.isAtomic()) { + updatedtypemap=new Hashtable>(); + updatedfieldmap=new Hashtable>(); + computeReadOnly(lb, updatedtypemap, updatedfieldmap); + } + for(Iterator fnit=fm.getNodeSet().iterator();fnit.hasNext();) { FlatNode fn=fnit.next(); - //Check whether this node matters for cannot delayed computation if (cannotdelaymap!=null&&cannotdelaymap.containsKey(lb)&&cannotdelaymap.get(lb).contains(fn)==inclusive) continue; Hashtable atomictable=locality.getAtomic(lb); - if (atomictable.get(fn).intValue()>0) { Hashtable> tmap=fnmap.get(fn); switch(fn.kind()) { @@ -314,6 +429,12 @@ public class DiscoverConflicts { if (tfpset!=null) tfset.addAll(tfpset); } + if (updatedtypemap!=null&&updatedtypemap.get(fen).contains(fen.getSrc().getType())) { + //this could cause conflict...figure out conflict set + Set tfpset=tmap.get(fen.getSrc()); + if (tfpset!=null) + writeset.addAll(tfpset); + } break; } case FKind.FlatFieldNode: { @@ -324,6 +445,12 @@ public class DiscoverConflicts { if (tfpset!=null) tfset.addAll(tfpset); } + if (updatedfieldmap!=null&&updatedfieldmap.get(ffn).contains(ffn.getField())) { + //this could cause conflict...figure out conflict set + Set tfpset=tmap.get(ffn.getSrc()); + if (tfpset!=null) + writeset.addAll(tfpset); + } break; } case FKind.FlatSetFieldNode: { @@ -332,6 +459,10 @@ public class DiscoverConflicts { Set tfpset=tmap.get(fsfn.getDst()); if (tfpset!=null) tfset.addAll(tfpset); + if (writeset!=null) { + if (tfpset!=null) + writeset.addAll(tfpset); + } break; } case FKind.FlatSetElementNode: { @@ -340,6 +471,10 @@ public class DiscoverConflicts { Set tfpset=tmap.get(fsen.getDst()); if (tfpset!=null) tfset.addAll(tfpset); + if (writeset!=null) { + if (tfpset!=null) + writeset.addAll(tfpset); + } break; } case FKind.FlatCall: //assume pessimistically that calls do bad things @@ -350,6 +485,10 @@ public class DiscoverConflicts { Set tfpset=tmap.get(rtmp); if (tfpset!=null) tfset.addAll(tfpset); + if (writeset!=null) { + if (tfpset!=null) + writeset.addAll(tfpset); + } } break; } diff --git a/Robust/src/IR/Flat/BuildCode.java b/Robust/src/IR/Flat/BuildCode.java index 80a21860..8b0b8f67 100644 --- a/Robust/src/IR/Flat/BuildCode.java +++ b/Robust/src/IR/Flat/BuildCode.java @@ -108,7 +108,7 @@ public class BuildCode { } if (state.SINGLETM&&state.DCOPTS) { TypeAnalysis typeanalysis=new TypeAnalysis(locality, st, typeutil,callgraph); - this.dc=new DiscoverConflicts(locality, st, typeanalysis); + this.dc=new DiscoverConflicts(locality, st, typeanalysis, null); dc.doAnalysis(); } if (state.DELAYCOMP) { @@ -118,7 +118,8 @@ public class BuildCode { delaycomp=new DelayComputation(locality, st, typeanalysis, gft); delaycomp.doAnalysis(); dc=delaycomp.getConflicts(); - recorddc=new DiscoverConflicts(locality, st, typeanalysis, delaycomp.getCannotDelayMap(), true, true); + recorddc=new DiscoverConflicts(locality, st, typeanalysis, delaycomp.getCannotDelayMap(), true, true, null); + recorddc.doAnalysis(); } if(state.MLP) { @@ -1582,7 +1583,9 @@ public class BuildCode { } //turn off write barrier generation wb.turnoff(); + state.SINGLETM=false; generateCode(faen, fm, lb, exitset, output, false); + state.SINGLETM=true; //turn on write barrier generation wb.turnon(); output.println("}\n\n"); @@ -2000,7 +2003,7 @@ public class BuildCode { if (recorddc.getNeedTrans(lb, current_node)) { output.println("STOREPTR("+generateTemp(fm, wrtmp,lb)+");"); } else { - output.println("STOREPTRNOTRANS("+generateTemp(fm, wrtmp,lb)+");"); + output.println("STOREPTRNOLOCK("+generateTemp(fm, wrtmp,lb)+");"); } } else { output.println("STORE"+wrtmp.getType().getSafeDescriptor()+"("+generateTemp(fm, wrtmp, lb)+");"); @@ -2459,9 +2462,11 @@ public class BuildCode { if (state.DSM) { output.println("TRANSREAD("+generateTemp(fm, fgcn.getSrc(),lb)+", (unsigned int) "+generateTemp(fm, fgcn.getSrc(),lb)+");"); } else { - if ((dc==null)||dc.getNeedTrans(lb, fgcn)) { + if ((dc==null)||!state.READSET&&dc.getNeedTrans(lb, fgcn)||state.READSET&&dc.getNeedWriteTrans(lb, fgcn)) { //need to do translation output.println("TRANSREAD("+generateTemp(fm, fgcn.getSrc(),lb)+", "+generateTemp(fm, fgcn.getSrc(),lb)+", (void *)("+localsprefixaddr+"));"); + } else if (state.READSET&&dc.getNeedTrans(lb, fgcn)) { + output.println("TRANSREADRD("+generateTemp(fm, fgcn.getSrc(),lb)+", "+generateTemp(fm, fgcn.getSrc(),lb)+");"); } } } else { @@ -2825,9 +2830,13 @@ public class BuildCode { output.println(dst+"="+ src +"->"+field+ ";"); if (ffn.getField().getType().isPtr()&&locality.getAtomic(lb).get(ffn).intValue()>0&& - ((dc==null)||dc.getNeedTrans(lb, ffn))&& locality.getNodePreTempInfo(lb, ffn).get(ffn.getSrc())!=LocalityAnalysis.SCRATCH) { - output.println("TRANSREAD("+dst+", "+dst+", (void *) (" + localsprefixaddr + "));"); + if ((dc==null)||(!state.READSET&&dc.getNeedTrans(lb, ffn))|| + (state.READSET&&dc.getNeedWriteTrans(lb, ffn))) { + output.println("TRANSREAD("+dst+", "+dst+", (void *) (" + localsprefixaddr + "));"); + } else if (state.READSET&&dc.getNeedTrans(lb, ffn)) { + output.println("TRANSREADRD("+dst+", "+dst+");"); + } } } else if (state.DSM) { Integer status=locality.getNodePreTempInfo(lb,ffn).get(ffn.getSrc()); @@ -2996,9 +3005,12 @@ public class BuildCode { output.println(dst +"=(("+ type+"*)(((char *) &("+ generateTemp(fm,fen.getSrc(),lb)+"->___length___))+sizeof(int)))["+generateTemp(fm, fen.getIndex(),lb)+"];"); if (elementtype.isPtr()&&locality.getAtomic(lb).get(fen).intValue()>0&& - ((dc==null)||dc.getNeedTrans(lb, fen))&& locality.getNodePreTempInfo(lb, fen).get(fen.getSrc())!=LocalityAnalysis.SCRATCH) { - output.println("TRANSREAD("+dst+", "+dst+", (void *)(" + localsprefixaddr+"));"); + if ((dc==null)||!state.READSET&&dc.getNeedTrans(lb, fen)||state.READSET&&dc.getNeedWriteTrans(lb, fen)) { + output.println("TRANSREAD("+dst+", "+dst+", (void *)(" + localsprefixaddr+"));"); + } else if (state.READSET&&dc.getNeedTrans(lb, fen)) { + output.println("TRANSREADRD("+dst+", "+dst+");"); + } } } else if (state.DSM) { Integer status=locality.getNodePreTempInfo(lb,fen).get(fen.getSrc()); @@ -3222,7 +3234,7 @@ public class BuildCode { private void generateFlatCastNode(FlatMethod fm, LocalityBinding lb, FlatCastNode fcn, PrintWriter output) { /* TODO: Do type check here */ if (fcn.getType().isArray()) { - throw new Error(); + output.println(generateTemp(fm,fcn.getDst(),lb)+"=(struct ArrayObject *)"+generateTemp(fm,fcn.getSrc(),lb)+";"); } else if (fcn.getType().isClass()) output.println(generateTemp(fm,fcn.getDst(),lb)+"=(struct "+fcn.getType().getSafeSymbol()+" *)"+generateTemp(fm,fcn.getSrc(),lb)+";"); else diff --git a/Robust/src/IR/State.java b/Robust/src/IR/State.java index bfbf60a8..5ac95d18 100644 --- a/Robust/src/IR/State.java +++ b/Robust/src/IR/State.java @@ -82,6 +82,7 @@ public class State { public static boolean PRINTCRITICALPATH=false; public static boolean ABORTREADERS=false; public static boolean SINGLETM=false; + public static boolean READSET=false; public int CORENUM = 1; public String structfile; public String main; diff --git a/Robust/src/IR/TypeDescriptor.java b/Robust/src/IR/TypeDescriptor.java index 7725f610..f039f652 100644 --- a/Robust/src/IR/TypeDescriptor.java +++ b/Robust/src/IR/TypeDescriptor.java @@ -68,7 +68,7 @@ public class TypeDescriptor extends Descriptor { name.equals("charwrapper")|| name.equals("floatwrapper")|| name.equals("doublewrapper")|| - name.equals("objectwrapper")); + name.equals("Objectwrapper")); } public TypeDescriptor makeArray(State state) { diff --git a/Robust/src/buildscript b/Robust/src/buildscript index c08ee9df..193a09b2 100755 --- a/Robust/src/buildscript +++ b/Robust/src/buildscript @@ -4,6 +4,7 @@ printhelp() { echo -robustroot set up the ROBUSTROOT to directory other than default one echo -dsm distributed shared memory echo -singleTM single machine committing transactions +echo -readset turn on readset echo -stmdebug STM debug echo "-stmstats prints single machine commit (stm) statistics for the benchmark" echo -fastmemcpy use fast memcpy @@ -60,6 +61,7 @@ echo -profile build with profile options echo "-useio use standard io to output profiling data (should be used together with -raw and -profile), it only works with single core version" echo "-enable-assertions execute assert statements during compilation" echo -justanalyze exit after compiler analyses complete +echo -assembly generate assembly echo -help help } @@ -99,6 +101,7 @@ JAVAFORWARDOPTS='' JAVAOPTS='' OPTIONALFLAG=false EXITAFTERANALYSIS=false +ASSEMBLY=false if [[ -z $1 ]] then @@ -115,6 +118,9 @@ exit elif [[ $1 = '-justanalyze' ]] then EXITAFTERANALYSIS=true +elif [[ $1 = '-assembly' ]] +then +ASSEMBLY=true elif [[ $1 = '-abortreaders' ]] then ABORTREADERS=true @@ -170,6 +176,10 @@ then JAVAOPTS="$JAVAOPTS -singleTM" EXTRAOPTIONS="$EXTRAOPTIONS -DSTM" SINGLETM=true +elif [[ $1 = '-readset' ]] +then +JAVAOPTS="$JAVAOPTS -readset" +EXTRAOPTIONS="$EXTRAOPTIONS -DREADSET" elif [[ $1 = '-stmdebug' ]] then EXTRAOPTIONS="$EXTRAOPTIONS -DSTMDEBUG" @@ -684,6 +694,12 @@ then EXTRAOPTIONS="$EXTRAOPTIONS -ldmalloc -DDMALLOC" fi +if $ASSEMBLY +then +gcc -S $INCLUDES $EXTRAOPTIONS -DPRECISE_GC \ +-c tmpbuilddirectory/methods.c -lm +fi + if $MULTICOREFLAG then gcc $INCLUDES $EXTRAOPTIONS \ @@ -693,6 +709,7 @@ gcc $INCLUDES $EXTRAOPTIONS -DPRECISE_GC \ tmpbuilddirectory/methods.c $FILES -lm -o $MAINFILE.bin fi + fi #!RAWFLAG exit -- 2.34.1