check in new files...
authorbdemsky <bdemsky>
Fri, 6 Nov 2009 02:45:40 +0000 (02:45 +0000)
committerbdemsky <bdemsky>
Fri, 6 Nov 2009 02:45:40 +0000 (02:45 +0000)
Robust/src/Analysis/Locality/DCWrapper.java [new file with mode: 0644]
Robust/src/Runtime/STM/inlinestm.h [new file with mode: 0644]

diff --git a/Robust/src/Analysis/Locality/DCWrapper.java b/Robust/src/Analysis/Locality/DCWrapper.java
new file mode 100644 (file)
index 0000000..f7d78f0
--- /dev/null
@@ -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<LocalityBinding> localityset=locality.getLocalityBindings();
+    for(Iterator<LocalityBinding> lbit=localityset.iterator();lbit.hasNext();) {
+      processlb(lbit.next());
+    }
+  }
+  
+  Hashtable<LocalityBinding, Set<FlatNode>> transmap=new Hashtable<LocalityBinding, Set<FlatNode>>();
+  Hashtable<LocalityBinding, Set<FlatNode>> recordmap=new Hashtable<LocalityBinding, Set<FlatNode>>();
+  Hashtable<LocalityBinding, Set<FlatNode>> othermap=new Hashtable<LocalityBinding, Set<FlatNode>>();
+  Hashtable<LocalityBinding, Set<FlatNode>> notreadymap=new Hashtable<LocalityBinding, Set<FlatNode>>();
+  Hashtable<LocalityBinding, HashSet<FlatNode>> cannotdelaymap=new Hashtable<LocalityBinding, HashSet<FlatNode>>();
+  Hashtable<LocalityBinding, Set<FlatNode>> derefmap=new Hashtable<LocalityBinding, Set<FlatNode>>();
+  
+  public DiscoverConflicts getConflicts() {
+    return delaycomp.getConflicts();
+  }
+  
+  public Hashtable<LocalityBinding, HashSet<FlatNode>> getCannotDelayMap() {
+    return cannotdelaymap;
+  }
+
+  public boolean needsFission(LocalityBinding lb, FlatAtomicEnterNode faen) {
+    return transmap.get(lb).contains(faen);
+  }
+
+  public Set<TempDescriptor> liveinto(LocalityBinding lb, FlatAtomicEnterNode faen, Set<FlatNode> recordset) {
+    return delaycomp.liveinto(lb, faen, recordset);
+  }
+
+  public Set<TempDescriptor> alltemps(LocalityBinding lb, FlatAtomicEnterNode faen, Set<FlatNode> recordset) {
+    return delaycomp.alltemps(lb, faen, recordset);
+  }
+
+  public Set<TempDescriptor> liveout(LocalityBinding lb, FlatAtomicEnterNode faen) {
+    return delaycomp.liveout(lb, faen);
+  }
+
+  public Set<TempDescriptor> liveoutvirtualread(LocalityBinding lb, FlatAtomicEnterNode faen) {
+    return delaycomp.liveoutvirtualread(lb, faen);
+  }
+
+  private static HashSet<FlatNode> intersect(Set<FlatNode> a, Set<FlatNode> b) {
+    HashSet<FlatNode> intersect=new HashSet(b);
+    intersect.retainAll(a);
+    return intersect;
+  }
+
+  public Set<FlatNode> getDeref(LocalityBinding lb) {
+    return derefmap.get(lb);
+  }
+
+  public Set<FlatNode> getNotReady(LocalityBinding lb) {
+    return notreadymap.get(lb);
+  }
+
+  public Set<FlatNode> getCannotDelay(LocalityBinding lb) {
+    return cannotdelaymap.get(lb);
+  }
+
+  public Set<FlatNode> getOther(LocalityBinding lb) {
+    return othermap.get(lb);
+  }
+
+  public Set<FlatNode> livecode(LocalityBinding lb) {
+    return recordmap.get(lb);
+  }
+
+  private void processlb(LocalityBinding lb) {
+    transmap.put(lb, new HashSet<FlatNode>());
+    if (lb.isAtomic()||!lb.getHasAtomic())
+      return;
+    
+    Set<FlatNode> recordset=delaycomp.livecode(lb);
+    Set<FlatNode> cannotdelay=delaycomp.getCannotDelay(lb);
+    Set<FlatNode> otherset=delaycomp.getOther(lb);
+    Set<FlatNode> notreadyset=delaycomp.getNotReady(lb);
+    Set<FlatNode> derefset=(state.STMARRAY&&!state.DUALVIEW)?delaycomp.getDeref(lb):null;
+    Set<FlatNode> checkset=new HashSet<FlatNode>();
+    checkset.addAll(cannotdelay);
+    checkset.addAll(otherset);
+
+    Set<FlatNode> nrecordset=new HashSet<FlatNode>();
+    HashSet<FlatNode> ncannotdelay=new HashSet<FlatNode>();
+    Set<FlatNode> notherset=new HashSet<FlatNode>();
+    Set<FlatNode> nnotready=new HashSet<FlatNode>();
+    Set<FlatNode> nderef=new HashSet<FlatNode>();
+
+    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<FlatNode> 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<FlatNode> transSet=computeTrans(lb, fn);
+       Set<FlatNode> tCheckSet=intersect(checkset, transSet);
+       Set<FlatNode> tRecordSet=intersect(recordset, transSet);
+       Set<FlatNode> tOtherSet=intersect(otherset, transSet);
+       Set<FlatNode> tNotReadySet=intersect(notreadyset, transSet);
+       HashSet<FlatNode> tCannotDelay=intersect(cannotdelay, transSet);
+       Set<FlatNode> 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<FlatNode>());
+       lwmap.get(lb).add(fn);
+      } else {
+       if (locality.getAtomic(lb).get(fn).intValue()==0)
+         ncannotdelay.add(fn);
+      }
+    }
+  }
+
+  Hashtable<LocalityBinding, Set<FlatNode>> lwmap=new Hashtable<LocalityBinding, Set<FlatNode>>();
+  Hashtable<LocalityBinding, Set<FlatNode>> optmap=new Hashtable<LocalityBinding, Set<FlatNode>>();
+
+  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<FlatNode> checkset, Set<FlatNode> recordset, LocalityBinding lb) {
+    if (!optmap.containsKey(lb)) {
+      optmap.put(lb, new HashSet<FlatNode>());
+    }
+    DiscoverConflicts dc=delaycomp.getConflicts();
+    for(Iterator<FlatNode> 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<FlatNode> computeTrans(LocalityBinding lb, FlatNode faen) {
+    HashSet<FlatNode> transSet=new HashSet<FlatNode>();
+    HashSet<FlatNode> toProcess=new HashSet<FlatNode>();
+    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;i<fn.numNext();i++) {
+       if (!transSet.contains(fn.getNext(i)))
+         toProcess.add(fn.getNext(i));
+      }
+    }
+    return transSet;
+  }
+}
\ No newline at end of file
diff --git a/Robust/src/Runtime/STM/inlinestm.h b/Robust/src/Runtime/STM/inlinestm.h
new file mode 100644 (file)
index 0000000..2803cda
--- /dev/null
@@ -0,0 +1,165 @@
+#ifndef INLINESTM_H
+#define INLINESTM_H
+#ifdef DELAYCOMP
+
+#ifndef READSET
+#define CHECKREADS(x) 0
+#endif
+
+#define LIGHTWEIGHTCOMMIT(commitmethod, primitives, locals, params, label) \
+  if (GETLOCKS()||CHECKREADS()) {                                      \
+    if (unlikely(needtocollect)) checkcollect(&___locals___);          \
+    goto label;                                                                \
+  }                                                                    \
+  ptrstack.maxcount=0;                                                 \
+  primstack.count=0;                                                   \
+  branchstack.count=0;                                                 \
+  commitmethod(params, locals, primitives);                            \
+  RELEASELOCKS();                                                      \
+  FREELIST();
+
+#ifdef READSET
+static inline int CHECKREADS() {
+  rdchashlistnode_t *rd_curr=rd_c_list;
+  int retval=0;
+  rdchashlistnode_t *ptr=rd_c_table;
+  rdchashlistnode_t *top=&ptr[rd_c_size];
+
+  while(likely(rd_curr!=NULL)) {
+    unsigned int version=rd_curr->version;
+    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_curr<top)) {
+      //zero in list
+      rd_curr->key=NULL;
+      rd_curr->next=NULL;
+    }
+    rd_curr=rd_curr->lnext;
+  }
+
+  if (unlikely(retval)) {
+    while(likely(rd_curr!=NULL)) {
+      if (likely(rd_curr>=ptr&&rd_curr<top)) {
+       //zero in list
+       rd_curr->key=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&&tmpptr<top) {
+      /*zero in list   */
+      tmpptr->key=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