From 70f4bc7c5de609c9091bee6006239102f03413f3 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Fri, 6 Nov 2009 02:45:40 +0000 Subject: [PATCH] check in new files... --- Robust/src/Analysis/Locality/DCWrapper.java | 204 ++++++++++++++++++++ Robust/src/Runtime/STM/inlinestm.h | 165 ++++++++++++++++ 2 files changed, 369 insertions(+) create mode 100644 Robust/src/Analysis/Locality/DCWrapper.java create mode 100644 Robust/src/Runtime/STM/inlinestm.h diff --git a/Robust/src/Analysis/Locality/DCWrapper.java b/Robust/src/Analysis/Locality/DCWrapper.java new file mode 100644 index 00000000..f7d78f0f --- /dev/null +++ b/Robust/src/Analysis/Locality/DCWrapper.java @@ -0,0 +1,204 @@ +package Analysis.Locality; +import Analysis.Liveness; +import Analysis.ReachingDefs; +import Analysis.Loops.DomTree; +import IR.State; +import IR.MethodDescriptor; +import IR.TypeDescriptor; +import IR.FieldDescriptor; +import IR.Flat.*; +import Analysis.Loops.GlobalFieldType; +import java.util.HashSet; +import java.util.Hashtable; +import java.util.Set; +import java.util.List; +import java.util.Arrays; +import java.util.Stack; +import java.util.Iterator; + +public class DCWrapper { + DelayComputation delaycomp; + State state; + LocalityAnalysis locality; + + public DCWrapper(LocalityAnalysis locality, State state, TypeAnalysis typeanalysis, GlobalFieldType gft) { + delaycomp=new DelayComputation(locality, state, typeanalysis, gft); + delaycomp.doAnalysis(); + this.state=state; + this.locality=locality; + Set localityset=locality.getLocalityBindings(); + for(Iterator lbit=localityset.iterator();lbit.hasNext();) { + processlb(lbit.next()); + } + } + + Hashtable> transmap=new Hashtable>(); + Hashtable> recordmap=new Hashtable>(); + Hashtable> othermap=new Hashtable>(); + Hashtable> notreadymap=new Hashtable>(); + Hashtable> cannotdelaymap=new Hashtable>(); + Hashtable> derefmap=new Hashtable>(); + + public DiscoverConflicts getConflicts() { + return delaycomp.getConflicts(); + } + + public Hashtable> getCannotDelayMap() { + return cannotdelaymap; + } + + public boolean needsFission(LocalityBinding lb, FlatAtomicEnterNode faen) { + return transmap.get(lb).contains(faen); + } + + public Set liveinto(LocalityBinding lb, FlatAtomicEnterNode faen, Set recordset) { + return delaycomp.liveinto(lb, faen, recordset); + } + + public Set alltemps(LocalityBinding lb, FlatAtomicEnterNode faen, Set recordset) { + return delaycomp.alltemps(lb, faen, recordset); + } + + public Set liveout(LocalityBinding lb, FlatAtomicEnterNode faen) { + return delaycomp.liveout(lb, faen); + } + + public Set liveoutvirtualread(LocalityBinding lb, FlatAtomicEnterNode faen) { + return delaycomp.liveoutvirtualread(lb, faen); + } + + private static HashSet intersect(Set a, Set b) { + HashSet intersect=new HashSet(b); + intersect.retainAll(a); + return intersect; + } + + public Set getDeref(LocalityBinding lb) { + return derefmap.get(lb); + } + + public Set getNotReady(LocalityBinding lb) { + return notreadymap.get(lb); + } + + public Set getCannotDelay(LocalityBinding lb) { + return cannotdelaymap.get(lb); + } + + public Set getOther(LocalityBinding lb) { + return othermap.get(lb); + } + + public Set livecode(LocalityBinding lb) { + return recordmap.get(lb); + } + + private void processlb(LocalityBinding lb) { + transmap.put(lb, new HashSet()); + if (lb.isAtomic()||!lb.getHasAtomic()) + return; + + Set recordset=delaycomp.livecode(lb); + Set cannotdelay=delaycomp.getCannotDelay(lb); + Set otherset=delaycomp.getOther(lb); + Set notreadyset=delaycomp.getNotReady(lb); + Set derefset=(state.STMARRAY&&!state.DUALVIEW)?delaycomp.getDeref(lb):null; + Set checkset=new HashSet(); + checkset.addAll(cannotdelay); + checkset.addAll(otherset); + + Set nrecordset=new HashSet(); + HashSet ncannotdelay=new HashSet(); + Set notherset=new HashSet(); + Set nnotready=new HashSet(); + Set nderef=new HashSet(); + + recordmap.put(lb, nrecordset); + cannotdelaymap.put(lb, ncannotdelay); + notreadymap.put(lb, nnotready); + othermap.put(lb, notherset); + derefmap.put(lb, nderef); + + FlatMethod fm=state.getMethodFlat(lb.getMethod()); + for(Iterator fnit=fm.getNodeSet().iterator();fnit.hasNext();) { + FlatNode fn=fnit.next(); + if (fn.kind()==FKind.FlatAtomicEnterNode&& + locality.getAtomic(lb).get(fn.getPrev(0)).intValue()==0) { + Set transSet=computeTrans(lb, fn); + Set tCheckSet=intersect(checkset, transSet); + Set tRecordSet=intersect(recordset, transSet); + Set tOtherSet=intersect(otherset, transSet); + Set tNotReadySet=intersect(notreadyset, transSet); + HashSet tCannotDelay=intersect(cannotdelay, transSet); + Set tderef=(state.STMARRAY&&!state.DUALVIEW)?intersect(derefset, transSet):null; + + if (checkSet(fn, tCheckSet, tRecordSet, lb)) { + //We will convert this one + nrecordset.addAll(tRecordSet); + notherset.addAll(tOtherSet); + nnotready.addAll(tNotReadySet); + ncannotdelay.addAll(tCannotDelay); + if (state.STMARRAY&&!state.DUALVIEW) + nderef.addAll(tderef); + transmap.get(lb).add(fn); + } else { + ncannotdelay.addAll(transSet); + } + if (!lwmap.containsKey(lb)) + lwmap.put(lb, new HashSet()); + lwmap.get(lb).add(fn); + } else { + if (locality.getAtomic(lb).get(fn).intValue()==0) + ncannotdelay.add(fn); + } + } + } + + Hashtable> lwmap=new Hashtable>(); + Hashtable> optmap=new Hashtable>(); + + public boolean lightweightTrans(LocalityBinding lb, FlatNode fn) { + return lwmap.get(lb).contains(fn); + } + + public boolean optimizeTrans(LocalityBinding lb, FlatNode fn) { + return optmap.get(lb).contains(fn); + } + + private boolean checkSet(FlatNode faen, Set checkset, Set recordset, LocalityBinding lb) { + if (!optmap.containsKey(lb)) { + optmap.put(lb, new HashSet()); + } + DiscoverConflicts dc=delaycomp.getConflicts(); + for(Iterator fnit=checkset.iterator();fnit.hasNext();) { + FlatNode fn=fnit.next(); + //needs transread + if (!state.READSET&&dc.getNeedTrans(lb, fn)||state.READSET&&dc.getNeedWriteTrans(lb, fn)) { + System.out.println("False because"+fn); + if (!state.HYBRID) + return true; + return false; + } + } + optmap.get(lb).add(faen); + return true; + } + + private Set computeTrans(LocalityBinding lb, FlatNode faen) { + HashSet transSet=new HashSet(); + HashSet toProcess=new HashSet(); + toProcess.add(faen); + while(!toProcess.isEmpty()) { + FlatNode fn=toProcess.iterator().next(); + toProcess.remove(fn); + transSet.add(fn); + if (locality.getAtomic(lb).get(fn).intValue()==0) + continue; + for(int i=0;iversion; + struct ___Object___ * objptr=rd_curr->key; + objheader_t *header=(objheader_t *)(((char *)objptr)-sizeof(objheader_t)); + if(likely(header->lock>0)) {//doesn't matter what type of lock... + if(unlikely(version!=header->version)) { + retval=1;break; + } + } else { + if(likely(version==header->version)) { + dchashlistnode_t *node = &dc_c_table[(((unsigned INTPTR)objptr) & dc_c_mask)>>4]; + do { + if(node->key == objptr) { + goto nextloop; + } + node = node->next; + } while(node!=NULL); + retval=1;break; + } + } + nextloop: + if (likely(rd_curr>=ptr&&rd_currkey=NULL; + rd_curr->next=NULL; + } + rd_curr=rd_curr->lnext; + } + + if (unlikely(retval)) { + while(likely(rd_curr!=NULL)) { + if (likely(rd_curr>=ptr&&rd_currkey=NULL; + rd_curr->next=NULL; + } + rd_curr=rd_curr->lnext; + } + while(rd_c_structs->next!=NULL) { + rdcliststruct_t *next=rd_c_structs->next; + free(rd_c_structs); + rd_c_structs=next; + } + rd_c_structs->num = 0; + rd_c_numelements = 0; + rd_c_list=NULL; + + lwreset(NULL); + return 1; + } + + while(rd_c_structs->next!=NULL) { + rdcliststruct_t *next=rd_c_structs->next; + free(rd_c_structs); + rd_c_structs=next; + } + rd_c_structs->num = 0; + rd_c_numelements = 0; + rd_c_list=NULL; + + return 0; +} +#endif + +static inline void FREELIST() { + dchashlistnode_t *ptr = dc_c_table; + dchashlistnode_t *top=&ptr[dc_c_size]; + dchashlistnode_t *tmpptr=dc_c_list; + while(tmpptr!=NULL) { + dchashlistnode_t *next=tmpptr->lnext; + if (tmpptr>=ptr&&tmpptrkey=NULL; + tmpptr->next=NULL; + } + tmpptr=next; + } + while(dc_c_structs->next!=NULL) { + dcliststruct_t *next=dc_c_structs->next; + free(dc_c_structs); + dc_c_structs=next; + } + dc_c_structs->num = 0; + dc_c_numelements = 0; + dc_c_list=NULL; +} + +static inline void RELEASELOCKS() { + dchashlistnode_t *dc_curr = dc_c_list; + while(likely(dc_curr!=NULL)) { + struct ___Object___ * objptr=dc_curr->key; + objheader_t *header=&((objheader_t *)objptr)[-1]; +#ifdef STMARRAY + if (objptr->type>=NUMCLASSES) { + rwwrite_unlock(&header->lock); + } else { +#endif + write_unlock(&header->lock); +#ifdef STMARRAY + } +#endif + dc_curr=dc_curr->lnext; + } + primstack.count=0; + ptrstack.count=0; + branchstack.count=0; +} + +static inline int GETLOCKS() { + dchashlistnode_t *dc_curr = dc_c_list; + while(likely(dc_curr!=NULL)) { + struct ___Object___ * objptr=dc_curr->key; + objheader_t *header=&((objheader_t *)objptr)[-1]; +#ifdef STMARRAY + if (objptr->type>=NUMCLASSES) { + if (unlikely(!rwwrite_trylock(&header->lock))) { +#ifdef READSET + rd_t_chashreset(); +#endif + lwreset(dc_curr); + return 1; + } + } else +#endif + if(unlikely(!write_trylock(&header->lock))) { +#ifdef READSET + rd_t_chashreset(); +#endif + lwreset(dc_curr); + return 1; + } + dc_curr=dc_curr->lnext; + } + return 0; +} + +#endif +#endif -- 2.34.1