more work towards supporting arrays
authorbdemsky <bdemsky>
Wed, 14 Oct 2009 20:38:04 +0000 (20:38 +0000)
committerbdemsky <bdemsky>
Wed, 14 Oct 2009 20:38:04 +0000 (20:38 +0000)
Robust/src/Analysis/Liveness.java
Robust/src/Analysis/ReachingDefs.java
Robust/src/Runtime/STM/commit.c

index 2b10f73945261569eda286197f4174a15169f7be..0c62d0b5f9e9734af032c743822f1a5da0a79931 100644 (file)
@@ -7,12 +7,16 @@ import java.util.Set;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Hashtable;
+import Analysis.Locality.*;
 
 public class Liveness {
   /* This methods takes in a FlatMethod and returns a map from a
    * FlatNode to the set of temps that are live into the FlatNode.*/
 
   public static Hashtable<FlatNode, Set<TempDescriptor>> computeLiveTemps(FlatMethod fm) {
+    return computeLiveTemps(fm, null);
+  }
+  public static Hashtable<FlatNode, Set<TempDescriptor>> computeLiveTemps(FlatMethod fm, LocalityBinding lb) {
     Hashtable<FlatNode, Set<TempDescriptor>> nodetotemps=new Hashtable<FlatNode, Set<TempDescriptor>>();
     
     Set<FlatNode> toprocess=fm.getNodeSet();
@@ -30,8 +34,11 @@ public class Liveness {
        if (nodetotemps.containsKey(fnnext))
          tempset.addAll(nodetotemps.get(fnnext));
       }
-      tempset.removeAll(writes);
-      tempset.addAll(reads);
+      if ((lb==null)||(!(fn instanceof FlatGlobalConvNode))||
+         ((FlatGlobalConvNode)fn).getLocality()==lb) {
+       tempset.removeAll(writes);
+       tempset.addAll(reads);
+      }
       if (!nodetotemps.containsKey(fn)||
           !nodetotemps.get(fn).equals(tempset)) {
        nodetotemps.put(fn, tempset);
@@ -43,7 +50,11 @@ public class Liveness {
   }
   
   public static Hashtable<FlatNode, Set<TempDescriptor>> computeLiveOut(FlatMethod fm) {
-    Hashtable<FlatNode, Set<TempDescriptor>> liveinmap=computeLiveTemps(fm);
+    return computeLiveOut(fm, null);
+  }
+
+  public static Hashtable<FlatNode, Set<TempDescriptor>> computeLiveOut(FlatMethod fm, LocalityBinding lb) {
+    Hashtable<FlatNode, Set<TempDescriptor>> liveinmap=computeLiveTemps(fm, lb);
     Hashtable<FlatNode, Set<TempDescriptor>> liveoutmap=new Hashtable<FlatNode, Set<TempDescriptor>>();
     
     for(Iterator<FlatNode> fnit=fm.getNodeSet().iterator(); fnit.hasNext();) {
index f10f3f26e34e2b9d4a9889e088b3959cb35e77a2..d0f3ebd288018cf1d5ae4ebaa5419c86240e90cd 100644 (file)
@@ -5,6 +5,7 @@ import java.util.HashSet;
 import java.util.Set;
 import java.util.Iterator;
 import java.util.Hashtable;
+import Analysis.Locality.*;
 
 public class ReachingDefs {
   /* This methods takes in a FlatMethod and returns a map from a
@@ -13,6 +14,10 @@ public class ReachingDefs {
   /* liveintoset if true computes the reaching defs into the node and if false computes the reaching defs out of the node. */
 
   public static Hashtable<FlatNode, Hashtable<TempDescriptor, Set<FlatNode>>> computeReachingDefs(FlatMethod fm, Hashtable<FlatNode, Set<TempDescriptor>> livemap, boolean liveintoset) {
+    return computeReachingDefs(fm, livemap, liveintoset, null);
+  }
+
+  public static Hashtable<FlatNode, Hashtable<TempDescriptor, Set<FlatNode>>> computeReachingDefs(FlatMethod fm, Hashtable<FlatNode, Set<TempDescriptor>> livemap, boolean liveintoset, LocalityBinding lb) {
     Hashtable<FlatNode, Hashtable<TempDescriptor, Set<FlatNode>>> nodetotemps=new Hashtable<FlatNode, Hashtable<TempDescriptor,Set<FlatNode>>>();
 
     Hashtable<FlatNode, Hashtable<TempDescriptor, Set<FlatNode>>> liveinto=liveintoset?new Hashtable<FlatNode, Hashtable<TempDescriptor,Set<FlatNode>>>():null;
@@ -47,13 +52,15 @@ public class ReachingDefs {
        liveinto.put(fn, new Hashtable<TempDescriptor, Set<FlatNode>>(tempset));
       }
       
-      TempDescriptor writes[]=fn.writesTemps();
-      for(int i=0;i<writes.length;i++) {
-       HashSet<FlatNode> s=new HashSet<FlatNode>();
-       s.add(fn);
-       tempset.put(writes[i],s);
+      if (lb==null||(!(fn instanceof FlatGlobalConvNode))||
+         ((FlatGlobalConvNode) fn).getLocality()==lb) {
+       TempDescriptor writes[]=fn.writesTemps();
+       for(int i=0;i<writes.length;i++) {
+         HashSet<FlatNode> s=new HashSet<FlatNode>();
+         s.add(fn);
+         tempset.put(writes[i],s);
+       }
       }
-
       if (!nodetotemps.containsKey(fn)||
           !nodetotemps.get(fn).equals(tempset)) {
        nodetotemps.put(fn, tempset);
@@ -63,5 +70,4 @@ public class ReachingDefs {
     }
     return liveintoset?liveinto:nodetotemps;
   }
-  
 }
\ No newline at end of file
index 912ceb38558c1a5a7922eca0d099f8ea1c6a3cd3..bda2038f0aa0dfd8ce2e8ae58a2415ba59900830 100644 (file)
@@ -238,6 +238,22 @@ int transCommit() {
   void * rdlockedarray[200];                   \
   void ** oidrdlockedarray;
 
+#define ARRAYABORT                                                     \
+  for(;j>=lowoffset;j--) {                                             \
+    GETLOCKVAL(status, transao, j);                                    \
+    if  (status==STMDIRTY) {                                           \
+      GETLOCKPTR(lockptr, mainao,j);                                   \
+      write_unlock(lockptr);                                           \
+    }                                                                  \
+  }                                                                    \
+  transAbortProcess(oidwrlocked, numoidwrlocked);                      \
+  freearrays;                                                          \
+  if (softabort)                                                       \
+    return TRANS_SOFT_ABORT;                                           \
+  else                                                                 \
+    return TRANS_ABORT;
+  
+
 #define PROCESSARRAY                                                   \
   int type=((int *)cachedobj)[0];                                      \
   if (type>=NUMCLASSES) {                                              \
@@ -261,14 +277,11 @@ int transCommit() {
          if (localversion == remoteversion) {                          \
            addwrobject=1;                                              \
          } else {                                                      \
-           dirwrlocked[numoidwrlocked++] = objptr;                     \
-           transAbortProcess(oidwrlocked, numoidwrlocked);             \
-           freearrays;                                                 \
-           if (softabort)                                              \
-             return TRANS_SOFT_ABORT;                                  \
-           else                                                        \
-             return TRANS_ABORT;                                       \
+           ARRAYABORT;                                                 \
          }                                                             \
+       } else {                                                        \
+         j--;                                                          \
+         ARRAYABORT;                                                   \
        }                                                               \
       } else if (status==STMCLEAN) {                                   \
        addrdobject=1;                                                  \
@@ -278,7 +291,7 @@ int transCommit() {
       dirwrlocked[numoidwrlocked++] = objptr;                          \
     }                                                                  \
     if (addrdobject) {                                                 \
-      rdlockedarray[numoidrdlockedarray++]=objptr;                             \
+      rdlockedarray[numoidrdlockedarray++]=objptr;                     \
     }                                                                  \
   } else                                                               
 
@@ -808,7 +821,28 @@ void transAbortProcess(struct garbagelist *oidwrlocked, int numoidwrlocked) {
   /* Release write locks */
   for(i=numoidwrlocked-1; i>=0; i--) {
     /* Read from the main heap */
-    header = &((objheader_t *)dirwrlocked[i])[-1];
+    struct ___Object___ * dst=dirwrlocked[i];
+    header = &((objheader_t *)dst)[-1];
+#ifdef STMARRAY
+    int type=dst->type;
+    if (type>=NUMCLASSES) {
+      //have array, do unlocking of bins
+      struct ArrayObject *src=(struct ArrayObject *)t_chashSearch(dst);
+      int lowoffset=(src->lowindex)>>INDEXSHIFT;
+      int highoffset=(src->highindex)>>INDEXSHIFT;
+      int j;
+      int addwrobject=0, addrdobject=0;
+      for(j=lowoffset; j<=highoffset;j++) {
+       int status;
+       GETLOCKVAL(status, src, j);
+       if (status==STMDIRTY) {
+         int *lockptr;
+         GETLOCKPTR(lockptr, ((struct ArrayObject *)dst), j);
+         write_unlock(lockptr);
+       }
+      }
+    } else
+#endif
     write_unlock(&header->lock);
   }
 #ifdef STMSTATS
@@ -860,7 +894,26 @@ void transCommitProcess(struct garbagelist * oidwrlocked, int numoidwrlocked) {
     struct ___Object___ *src=t_chashSearch(dst);
     dst->___cachedCode___=src->___cachedCode___;
     dst->___cachedHash___=src->___cachedHash___;
-    A_memcpy(&dst[1], &src[1], tmpsize-sizeof(struct ___Object___));
+#ifdef STMARRAY
+    int type=dst->type;
+    if (type>=NUMCLASSES) {
+      //have array, do copying of bins
+      int lowoffset=(((struct ArrayObject *)src)->lowindex)>>INDEXSHIFT;
+      int highoffset=(((struct ArrayObject *)src)->highindex)>>INDEXSHIFT;
+      int j;
+      int addwrobject=0, addrdobject=0;
+      int elementsize=classsize[type];
+      int baseoffset=(lowoffset*elementsize)&HIGHMASK;
+      for(j=lowoffset; j<=highoffset;j++, baseoffset+=elementsize) {
+       int status;
+       GETLOCKVAL(status, ((struct ArrayObject *)src), j);
+       if (status==STMDIRTY) {
+         A_memcpy(((char *)&oid[1])+baseoffset, ((char *)&orig[1])+baseoffset, INDEXLENGTH);
+       }
+      }
+    } else
+#endif 
+      A_memcpy(&dst[1], &src[1], tmpsize-sizeof(struct ___Object___));
   }
   CFENCE;
 
@@ -879,9 +932,34 @@ void transCommitProcess(struct garbagelist * oidwrlocked, int numoidwrlocked) {
 
   /* Release write locks */
   for(i=NUMWRTOTAL-1; i>=0; i--) {
-    header = &((objheader_t *)dirwrlocked[i])[-1];
-    header->version++;
-    write_unlock(&header->lock);
+    struct ___Object___ * dst=dirwrlocked[i];
+    header = &((objheader_t *)dst)[-1];
+#ifdef STMARRAY
+    int type=dst->type;
+    if (type>=NUMCLASSES) {
+      //have array, do unlocking of bins
+      struct ArrayObject *src=(struct ArrayObject *)t_chashSearch(dst);
+      int lowoffset=(src->lowindex)>>INDEXSHIFT;
+      int highoffset=(src->highindex)>>INDEXSHIFT;
+      int j;
+      int addwrobject=0, addrdobject=0;
+      for(j=lowoffset; j<=highoffset;j++) {
+       int status;
+       GETLOCKVAL(status, src, j);
+       if (status==STMDIRTY) {
+         int *ptr;
+         GETVERSIONPTR(intptr, ((struct ArrayObject *)dst), j);
+         (*intptr)++;
+         GETLOCKPTR(intptr, ((struct ArrayObject *)dst), j);
+         write_unlock(intptr);
+       }
+      }
+    } else
+#endif
+    {
+      header->version++;
+      write_unlock(&header->lock);
+    }
   }
 
 #ifdef STMSTATS