changes
authorbdemsky <bdemsky>
Thu, 15 Oct 2009 07:37:23 +0000 (07:37 +0000)
committerbdemsky <bdemsky>
Thu, 15 Oct 2009 07:37:23 +0000 (07:37 +0000)
Robust/src/Runtime/STM/array.h
Robust/src/Runtime/STM/commit.c
Robust/src/Runtime/STM/delaycomp.h
Robust/src/Runtime/STM/sandbox.c
Robust/src/Runtime/STM/stm.c
Robust/src/Runtime/STM/stmlock.h
Robust/src/Runtime/STM/stmlookup.c
Robust/src/Runtime/STM/stmlookup.h
Robust/src/Runtime/STM/tm.h
Robust/src/Runtime/garbage.c
Robust/src/Runtime/thread.c

index a4648e0801113918ce81aa5ca1fcb3536c85cc34..33b9fa642ee2f5e79b2906b51214b06ac957158f 100644 (file)
@@ -37,7 +37,7 @@
 #define STMGETARRAY(dst, array, index, type) {                         \
     int byteindex=index*sizeof(type);                                  \
     int * lengthoff=&array->___length___;                              \
-    if (array!=array->___objlocation___) {                             \
+    if (((char *)array)!=((char *)array->___objlocation___)) {         \
       if(!(array->___objstatus___&NEW)) {                              \
        int *status;                                                    \
        GETLOCKPTR(status, array, byteindex>>INDEXSHIFT);               \
index d52f3d1e2c57d716463bf15ef544af194c59e32e..34a8aaa898522a09749b2d73e418f65df3adacf3 100644 (file)
@@ -70,6 +70,9 @@ int transCommit() {
       ptrstack.count=0;
       primstack.count=0;
       branchstack.count=0;
+#ifdef STMARRAY
+      arraystack.count=0;
+#endif
 #endif
 #ifdef SANDBOX
       abortenabled=1;
@@ -90,6 +93,9 @@ int transCommit() {
       ptrstack.count=0;
       primstack.count=0;
       branchstack.count=0;
+#ifdef STMARRAY
+      arraystack.count=0;
+#endif
 #endif
       return 0;
     }
@@ -116,6 +122,9 @@ int transCommit() {
        ptrstack.count=0;
        primstack.count=0;
        branchstack.count=0;
+#ifdef STMARRAY
+      arraystack.count=0;
+#endif
 #endif
        return TRANS_ABORT;
       }
@@ -293,7 +302,7 @@ int transCommit() {
     if (addrdobject) {                                                 \
       oidrdlockedarray[numoidrdlockedarray++]=objptr;                  \
     }                                                                  \
-  } else                                                               
+  } else
 
 #define READARRAYS                                                     \
   for(i=0; i<numoidrdlockedarray; i++) {                               \
@@ -435,7 +444,7 @@ int transCommit() {
   //acquire access set locks
   unsigned int numoidwrtotal=numoidwrlocked;
 
-  chashlistnode_t *dc_curr = dc_c_list;
+  dchashlistnode_t *dc_curr = dc_c_list;
   /* Inner loop to traverse the linked list of the cache lookupTable */
   while(likely(dc_curr != NULL)) {
     //if the first bin in hash table is empty
@@ -542,7 +551,7 @@ int transCommit() {
 #ifdef DELAYCOMP
        //check to see if it is in the delaycomp table
        {
-         chashlistnode_t *node = &dc_c_table[(((unsigned INTPTR)key) & dc_c_mask)>>4];
+         dchashlistnode_t *node = &dc_c_table[(((unsigned INTPTR)key) & dc_c_mask)>>4];
          do {
            if(node->key == key)
              goto nextloopread;
@@ -667,7 +676,7 @@ int alttraverseCache() {
 #ifdef DELAYCOMP
   //acquire other locks
   unsigned int numoidwrtotal=numoidwrlocked;
-  chashlistnode_t *dc_curr = dc_c_list;
+  dchashlistnode_t *dc_curr = dc_c_list;
   /* Inner loop to traverse the linked list of the cache lookupTable */
   while(likely(dc_curr != NULL)) {
     //if the first bin in hash table is empty
@@ -769,7 +778,7 @@ int alttraverseCache() {
 #ifdef DELAYCOMP
        //check to see if it is in the delaycomp table
        {
-         chashlistnode_t *node = &dc_c_table[(((unsigned INTPTR)key) & dc_c_mask)>>4];
+         dchashlistnode_t *node = &dc_c_table[(((unsigned INTPTR)key) & dc_c_mask)>>4];
          do {
            if(node->key == key)
              goto nextloopread;
@@ -931,9 +940,12 @@ void transCommitProcess(struct garbagelist * oidwrlocked, int numoidwrlocked) {
 
 #ifdef DELAYCOMP
   //  call commit method
-  ptrstack.count=0;
+  ptrstack.maxcount=0;
   primstack.count=0;
   branchstack.count=0;
+#ifdef STMARRAY
+  arraystack.maxcount=0;
+#endif
   //splice oidwrlocked in
   oidwrlocked->size=numoidwrtotal;
   oidwrlocked->next=params;
index 1671999652d0f412020f30bc9e562557b8969e73..fcf081a67830d9af418a44141f8304aed0fb148b 100644 (file)
@@ -8,11 +8,14 @@
 #define MAXPOINTERS 1024*1024*1
 #define MAXVALUES 1024*1024*2
 #define MAXBRANCHES 1024*1024*4
+#define MAXARRAY 1024*1024
 
 struct pointerlist {
   int count;
   void * prev;
-  void * array[MAXPOINTERS+1024];
+  void * array[MAXPOINTERS];
+  int maxcount;
+  void * buffer[1024];
 };
 
 struct primitivelist {
@@ -28,10 +31,33 @@ struct branchlist {
 extern __thread struct pointerlist ptrstack;
 extern __thread struct primitivelist primstack;
 extern __thread struct branchlist branchstack;
+#ifdef STMARRAY
+struct arraylist {
+  int count;
+  void * prev;
+  void *array[MAXARRAY];
+  int maxcount;
+  int index[MAXARRAY+1024];
+};
+
+extern __thread struct arraylist arraystack;
+#endif
+
+//Arrays
+
+#define RESTOREARRAY(x,z) {x=arraystack.array[arraystack.maxcount];z=arraystack.index[arraystack.maxcount++];}
+
+#define STOREARRAY(x,z) {void * y=COMPOID(x); arraystack.array[arraystack.count]=y; arraystack.index[arraystack.count++]=z; dc_t_chashInsertOnce(y,y,z);}
+
+#define STOREARRAYNOLOCK(x,z) {void * y=COMPOID(x); arraystack.array[arraystack.count]=y; arraystack.index[arraystack.count++]=z;}
+
+#define STOREARRAYNOTRANS(x,z) {void * y=x; arraystack.array[arraystack.count]=y; arraystack.index[arraystack.count++]=z; dc_t_chashInsertOnce(y,y,z);}
+
+#define STOREARRAYNOLOCKNOTRANS(x,z) {void * y=x; arraystack.array[arraystack.count]=y; arraystack.index[arraystack.count++]=z; }
 
 //Pointers
 
-#define RESTOREPTR(x) x=ptrstack.array[ptrstack.count++];
+#define RESTOREPTR(x) x=ptrstack.array[ptrstack.maxcount++];
 
 #define STOREPTR(x) {void * y=COMPOID(x); ptrstack.array[ptrstack.count++]=y; dc_t_chashInsertOnce(y,y);}
 
index 052c0f16e945380013e1b4f3d161940a7db2728b..25194ed3431d87c9582700d426cda3a44d8468fb 100644 (file)
@@ -27,6 +27,9 @@ void checkObjects() {
     ptrstack.count=0;
     primstack.count=0;
     branchstack.count=0;
+#ifdef STMARRAY
+    arraystack.count=0;
+#endif
 #endif
     _longjmp(aborttrans, 1);
   }
@@ -55,6 +58,9 @@ void errorhandler(int sig, struct sigcontext ctx) {
     ptrstack.count=0;
     primstack.count=0;
     branchstack.count=0;
+#ifdef STMARRAY
+    arraystack.count=0;
+#endif
 #endif
     _longjmp(aborttrans, 1);
   }
index 45e4dd4cf577433b49efed386c65b6d3f1861054..e8a8aaab80cd38bf2cd658fb1181fd2471a59005 100644 (file)
@@ -27,9 +27,9 @@ __thread struct objlist * newobjs;
 __thread struct pointerlist ptrstack;
 __thread struct primitivelist primstack;
 __thread struct branchlist branchstack;
-struct pointerlist *c_ptrstack;
-struct primitivelist *c_primstack;
-struct branchlist *c_branchstack;
+#ifdef STMARRAY
+__thread struct arraylist arraystack;
+#endif
 #endif
 
 #ifdef TRANSSTATS
@@ -77,11 +77,6 @@ int stmStartup() {
  */
 void transStart() {
   //Transaction start is currently free...commit and aborting is not
-#ifdef DELAYCOMP
-  c_ptrstack=&ptrstack;
-  c_primstack=&primstack;
-  c_branchstack=&branchstack;
-#endif
 }
 
 /* =======================================================
index acc5f915925670d40495f291c640f70ff040ae73..fda204553bff72b33f75942a97c58dbb700b3f1f 100644 (file)
@@ -37,17 +37,17 @@ static inline void write_unlock(volatile unsigned int *lock) {
 }
 
 
-static inline void atomic_add(int i, unsigned int *v) {
+static inline void atomic_add(int i, volatile unsigned int *v) {
   __asm__ __volatile__ (LOCK_PREFIX "addl %1,%0"
                         : "+m" (*v)
                         : "ir" (i));
 }
 
-static inline void read_unlock(volatile unsigned int *rw) {
+static inline void rwread_unlock(volatile unsigned int *rw) {
   __asm__ __volatile__ (LOCK_PREFIX "incl %0" : "+m" (*rw) : : "memory");
 }
 
-static inline void write_unlock(volatile unsigned int *rw) {
+static inline void rwwrite_unlock(volatile unsigned int *rw) {
   __asm__ __volatile__ (LOCK_PREFIX "addl %1, %0"
                         : "+m" (*rw) : "i" (RW_LOCK_BIAS) : "memory");
 }
@@ -62,7 +62,7 @@ static inline void atomic_inc(volatile unsigned int *v) {
                         : "+m" (*v));
 }
 
-static inline int atomic_sub_and_test(int i, unsigned int *v) {
+static inline int atomic_sub_and_test(int i, volatile unsigned int *v) {
   unsigned char c;
 
   __asm__ __volatile__ (LOCK_PREFIX "subl %2,%0; sete %1"
@@ -73,7 +73,7 @@ static inline int atomic_sub_and_test(int i, unsigned int *v) {
 
 #define atomic_read(v)          (*v)
 
-static inline int read_trylock(volatile unsigned int  *lock) {
+static inline int rwread_trylock(volatile unsigned int  *lock) {
   atomic_dec(lock);
   if (atomic_read(lock) >= 0)
     return 1; //can aquire a new read lock
@@ -81,11 +81,11 @@ static inline int read_trylock(volatile unsigned int  *lock) {
   return 0; //failure
 }
 
-static inline int write_trylock(volatile unsigned int  *lock) {
-  if (atomic_sub_and_test(RW_LOCK_BIAS, *lock)) {
+static inline int rwwrite_trylock(volatile unsigned int  *lock) {
+  if (atomic_sub_and_test(RW_LOCK_BIAS, lock)) {
     return 1; // get a write lock
   }
-  atomic_add(RW_LOCK_BIAS, *lock);
+  atomic_add(RW_LOCK_BIAS, lock);
   return 0; // failed to acquire a write lock
 }
 #endif
index 12345be618cec1cf3cf323b6ceaad17620686914..594e3aeb53e298908641d335fc93cb49c4a95eba 100644 (file)
@@ -202,41 +202,40 @@ void rd_t_chashDelete() {
 #endif
 
 #ifdef DELAYCOMP
-__thread chashlistnode_t *dc_c_table;
-__thread chashlistnode_t *dc_c_list;
+__thread dchashlistnode_t *dc_c_table;
+__thread dchashlistnode_t *dc_c_list;
 __thread unsigned int dc_c_size;
 __thread unsigned INTPTR dc_c_mask;
 __thread unsigned int dc_c_numelements;
 __thread unsigned int dc_c_threshold;
 __thread double dc_c_loadfactor;
-__thread cliststruct_t *dc_c_structs;
+__thread dcliststruct_t *dc_c_structs;
 
 void dc_t_chashCreate(unsigned int size, double loadfactor) {
-  chashtable_t *ctable;
-  chashlistnode_t *nodes;
+  dchashlistnode_t *nodes;
   int i;
 
   // Allocate space for the hash table
 
-  dc_c_table = calloc(size, sizeof(chashlistnode_t));
+  dc_c_table = calloc(size, sizeof(dchashlistnode_t));
   dc_c_loadfactor = loadfactor;
   dc_c_size = size;
   dc_c_threshold=size*loadfactor;
   dc_c_mask = (size << 4)-1;
-  dc_c_structs=calloc(1, sizeof(cliststruct_t));
+  dc_c_structs=calloc(1, sizeof(dcliststruct_t));
   dc_c_numelements = 0; // Initial number of elements in the hash
   dc_c_list=NULL;
 }
 
 void dc_t_chashreset() {
-  chashlistnode_t *ptr = dc_c_table;
+  dchashlistnode_t *ptr = dc_c_table;
   int i;
 
   if (dc_c_numelements<(dc_c_size>>4)) {
-    chashlistnode_t *top=&ptr[dc_c_size];
-    chashlistnode_t *tmpptr=dc_c_list;
+    dchashlistnode_t *top=&ptr[dc_c_size];
+    dchashlistnode_t *tmpptr=dc_c_list;
     while(tmpptr!=NULL) {
-      chashlistnode_t *next=tmpptr->lnext;
+      dchashlistnode_t *next=tmpptr->lnext;
       if (tmpptr>=ptr&&tmpptr<top) {
        //zero in list
        tmpptr->key=NULL;
@@ -245,10 +244,10 @@ void dc_t_chashreset() {
       tmpptr=next;
     }
   } else {
-    bzero(dc_c_table, sizeof(chashlistnode_t)*dc_c_size);
+    bzero(dc_c_table, sizeof(dchashlistnode_t)*dc_c_size);
   }
   while(dc_c_structs->next!=NULL) {
-    cliststruct_t *next=dc_c_structs->next;
+    dcliststruct_t *next=dc_c_structs->next;
     free(dc_c_structs);
     dc_c_structs=next;
   }
@@ -259,7 +258,7 @@ void dc_t_chashreset() {
 
 //Store objects and their pointers into hash
 void dc_t_chashInsertOnce(void * key, void *val) {
-  chashlistnode_t *ptr;
+  dchashlistnode_t *ptr;
 
   if (key==NULL)
     return;
@@ -279,8 +278,8 @@ void dc_t_chashInsertOnce(void * key, void *val) {
     dc_c_list=ptr;
     dc_c_numelements++;
   } else { // Insert in the beginning of linked list
-    chashlistnode_t * node;
-    chashlistnode_t *search=ptr;
+    dchashlistnode_t * node;
+    dchashlistnode_t *search=ptr;
     
     //make sure it isn't here
     do {
@@ -296,13 +295,70 @@ void dc_t_chashInsertOnce(void * key, void *val) {
       dc_c_structs->num++;
     } else {
       //get new list
-      cliststruct_t *tcl=calloc(1,sizeof(cliststruct_t));
+      dcliststruct_t *tcl=calloc(1,sizeof(dcliststruct_t));
+      tcl->next=dc_c_structs;
+      dc_c_structs=tcl;
+      node=&tcl->array[0];
+      tcl->num=1;
+    }
+    node->key = key;
+    node->val = val;
+    node->next = ptr->next;
+    ptr->next=node;
+    node->lnext=dc_c_list;
+    dc_c_list=node;
+  }
+}
+
+#ifdef STMARRAY
+//Store objects and their pointers into hash
+void dc_t_chashInsertOnceArray(void * key, unsigned int intkey, void *val) {
+  dchashlistnode_t *ptr;
+
+  if (key==NULL)
+    return;
+
+  if(dc_c_numelements > (dc_c_threshold)) {
+    //Resize
+    unsigned int newsize = dc_c_size << 1;
+    dc_t_chashResize(newsize);
+  }
+
+  ptr = &dc_c_table[(((unsigned INTPTR)key^intkey)&dc_c_mask)>>4];
+
+  if(ptr->key==0) {
+    ptr->key=key;
+    ptr->intkey=intkey;
+    ptr->val=val;
+    ptr->lnext=dc_c_list;
+    dc_c_list=ptr;
+    dc_c_numelements++;
+  } else { // Insert in the beginning of linked list
+    dchashlistnode_t * node;
+    dchashlistnode_t *search=ptr;
+    
+    //make sure it isn't here
+    do {
+      if(search->key == key&&search->intkey==intkey) {
+       return;
+      }
+      search=search->next;
+    } while(search != NULL);
+
+    dc_c_numelements++;
+    if (dc_c_structs->num<NUMCLIST) {
+      node=&dc_c_structs->array[dc_c_structs->num];
+      dc_c_structs->num++;
+    } else {
+      //get new list
+      dcliststruct_t *tcl=calloc(1,sizeof(dcliststruct_t));
       tcl->next=dc_c_structs;
       dc_c_structs=tcl;
       node=&tcl->array[0];
       tcl->num=1;
     }
     node->key = key;
+    node->intkey = intkey;
     node->val = val;
     node->next = ptr->next;
     ptr->next=node;
@@ -310,9 +366,10 @@ void dc_t_chashInsertOnce(void * key, void *val) {
     dc_c_list=node;
   }
 }
+#endif
 
 unsigned int dc_t_chashResize(unsigned int newsize) {
-  chashlistnode_t *node, *ptr, *curr;    // curr and next keep track of the current and the next chashlistnodes in a linked list
+  dchashlistnode_t *node, *ptr, *curr;    // curr and next keep track of the current and the next chashlistnodes in a linked list
   unsigned int oldsize;
   int isfirst;    // Keeps track of the first element in the chashlistnode_t for each bin in hashtable
   unsigned int i,index;
@@ -322,7 +379,7 @@ unsigned int dc_t_chashResize(unsigned int newsize) {
   oldsize = dc_c_size;
   dc_c_list=NULL;
 
-  if((node = calloc(newsize, sizeof(chashlistnode_t))) == NULL) {
+  if((node = calloc(newsize, sizeof(dchashlistnode_t))) == NULL) {
     printf("Calloc error %s %d\n", __FILE__, __LINE__);
     return 1;
   }
@@ -337,17 +394,28 @@ unsigned int dc_t_chashResize(unsigned int newsize) {
     isfirst = 1;
     do {                      //Inner loop to go through linked lists
       void * key;
-      chashlistnode_t *tmp,*next;
+#ifdef STMARRAY
+      unsigned int intkey;
+#endif
+      dchashlistnode_t *tmp,*next;
 
       if ((key=curr->key) == 0) {             //Exit inner loop if there the first element is 0
        break;                  //key = val =0 for element if not present within the hash table
       }
+#ifdef STMARRAY
+      intkey=curr->intkey;
+      index = (((unsigned INTPTR)key^intkey) & mask) >>4;
+#else
       index = (((unsigned INTPTR)key) & mask) >>4;
+#endif
       tmp=&node[index];
       next = curr->next;
       // Insert into the new table
       if(tmp->key == 0) {
        tmp->key = key;
+#ifdef STMARRAY
+       tmp->intkey = intkey;
+#endif
        tmp->val = curr->val;
        tmp->lnext=dc_c_list;
        dc_c_list=tmp;
@@ -380,9 +448,9 @@ unsigned int dc_t_chashResize(unsigned int newsize) {
 //Delete the entire hash table
 void dc_t_chashDelete() {
   int i;
-  cliststruct_t *ptr=dc_c_structs;
+  dcliststruct_t *ptr=dc_c_structs;
   while(ptr!=NULL) {
-    cliststruct_t *next=ptr->next;
+    dcliststruct_t *next=ptr->next;
     free(ptr);
     ptr=next;
   }
@@ -395,7 +463,7 @@ void dc_t_chashDelete() {
 // Search for an address for a given oid
 INLINE void * dc_t_chashSearch(void * key) {
   //REMOVE HASH FUNCTION CALL TO MAKE SURE IT IS INLINED HERE
-  chashlistnode_t *node = &dc_c_table[(((unsigned INTPTR)key) & dc_c_mask)>>4];
+  dchashlistnode_t *node = &dc_c_table[(((unsigned INTPTR)key) & dc_c_mask)>>4];
   
   do {
     if(node->key == key) {
@@ -407,6 +475,23 @@ INLINE void * dc_t_chashSearch(void * key) {
   return NULL;
 }
 
+#ifdef STMARRAY
+// Search for an address for a given oid
+INLINE void * dc_t_chashSearchArray(void * key, unsigned int intkey) {
+  //REMOVE HASH FUNCTION CALL TO MAKE SURE IT IS INLINED HERE
+  dchashlistnode_t *node = &dc_c_table[(((unsigned INTPTR)key^intkey) & dc_c_mask)>>4];
+  
+  do {
+    if(node->key == key && node->intkey==intkey) {
+      return node->val;
+    }
+    node = node->next;
+  } while(node != NULL);
+
+  return NULL;
+}
+#endif
+
 #endif
 
 void t_chashCreate(unsigned int size, double loadfactor) {
index 378f1c98219320a3ab4951f44873d451c7786165..0d74e46ffcf7aa26c98d3cfb06c7bb692af6cf92 100644 (file)
@@ -90,14 +90,30 @@ void rd_t_chashreset();
 #endif
 
 #ifdef DELAYCOMP
-extern __thread chashlistnode_t *dc_c_table;
-extern __thread chashlistnode_t *dc_c_list;
+
+typedef struct dchashlistnode {
+  void * key;
+  unsigned int intkey;
+  void * val;     //this can be cast to another type or used to point to a larger structure
+  struct dchashlistnode *next;
+  struct dchashlistnode *lnext;
+} dchashlistnode_t;
+
+#define NUMDCLIST 250
+typedef struct dclist {
+  struct dchashlistnode array[NUMDCLIST];
+  int num;
+  struct dclist *next;
+} dcliststruct_t;
+
+extern __thread dchashlistnode_t *dc_c_table;
+extern __thread dchashlistnode_t *dc_c_list;
 extern __thread unsigned int dc_c_size;
 extern __thread unsigned INTPTR dc_c_mask;
 extern __thread unsigned int dc_c_numelements;
 extern __thread unsigned int dc_c_threshold;
 extern __thread double dc_c_loadfactor;
-extern __thread cliststruct_t *dc_c_structs;
+extern __thread dcliststruct_t *dc_c_structs;
 
 void dc_t_chashCreate(unsigned int size, double loadfactor);
 void dc_t_chashInsertOnce(void * key, void *val);
index faa297c54781a8950410b9dc8d7177240d330d07..250c4246522a5fc63a7ca617aa0b8b93169daa78 100644 (file)
@@ -8,7 +8,7 @@
 #define TRANS_SOFT_ABORT    12
 #define TRANS_ABORT         13
 #define TRANS_COMMIT        14
-#define TRANS_ABORT_RETRY         15
+#define TRANS_ABORT_RETRY   15
 
 /* ========================
  * Library header files
@@ -253,6 +253,7 @@ extern __thread int t_objnumcount;
 #endif
 
 #define likely(x) x
+#define unlikely(x) x
 
 extern void * curr_heapbase;
 extern void * curr_heapptr;
index a611cf174504914a70eb97ff8a8e024d65e9b551..44f4024f87d380106e9a712ae3bdc41dd442c17a 100644 (file)
@@ -302,6 +302,10 @@ void collect(struct garbagelist * stackptr) {
 #ifdef DELAYCOMP
   ptrstack.prev=stackptr;
   stackptr=(struct garbagelist *) &ptrstack;
+#ifdef STMARRAY
+  arraystack.prev=stackptr;
+  stackptr=(struct garbagelist *) &arraystack;
+#endif
 #endif
 
 #ifdef GARBAGESTATS
@@ -641,6 +645,10 @@ void stopforgc(struct garbagelist * ptr) {
   //just append us to the list
   ptrstack.prev=ptr;
   ptr=(struct garbagelist *) &ptrstack;
+#ifdef STMARRAY
+  arraystack.prev=ptr;
+  ptr=(struct garbagelist *) &arraystack;
+#endif
 #endif
 #ifndef MAC
   litem.stackptr=ptr;
index 5244d3064bab5f18dac22a54c0b986eab14fc515..3632b3612d2364132ab123ae59ae08e7cbc9c9f4 100644 (file)
@@ -199,7 +199,10 @@ void initializethreads() {
   ptrstack.count=0;
   primstack.count=0;
   branchstack.count=0;
-  int a=mprotect((downpage(&ptrstack.array[MAXPOINTERS])), 4096, PROT_NONE);
+#ifdef STMARRAY
+  arraystack.count=0;
+#endif
+  int a=mprotect((downpage(&ptrstack.buffer[0])), 4096, PROT_NONE);
   if (a==-1)
     perror("ptrstack");
   a=mprotect(downpage(&primstack.array[MAXVALUES]), 4096, PROT_NONE);
@@ -208,6 +211,11 @@ void initializethreads() {
   a=mprotect(downpage(&branchstack.array[MAXBRANCHES]), 4096, PROT_NONE);
   if (a==-1)
     perror("branchstack");
+#ifdef STMARRAY
+  a=mprotect(downpage(&arraystack.index[MAXARRAY]), 4096, PROT_NONE);
+  if (a==-1)
+    perror("arraystack");
+#endif
 #endif
 #ifdef STMSTATS
   trec=calloc(1, sizeof(threadrec_t));
@@ -292,7 +300,10 @@ void initthread(struct ___Thread___ * ___this___) {
   ptrstack.count=0;
   primstack.count=0;
   branchstack.count=0;
-  int a=mprotect(downpage(&ptrstack.array[MAXPOINTERS]), 4096, PROT_NONE);
+#ifdef STMARRAY
+  arraystack.count=0;
+#endif
+  int a=mprotect(downpage(&ptrstack.buffer[0]), 4096, PROT_NONE);
   if (a==-1)
     perror("ptrstack");
   a=mprotect(downpage(&primstack.array[MAXVALUES]), 4096, PROT_NONE);
@@ -301,6 +312,11 @@ void initthread(struct ___Thread___ * ___this___) {
   a=mprotect(downpage(&branchstack.array[MAXBRANCHES]), 4096, PROT_NONE);
   if (a==-1)
     perror("branchstack");
+#ifdef STMARRAY
+  a=mprotect(downpage(&arraystack.index[MAXARRAY]), 4096, PROT_NONE);
+  if (a==-1)
+    perror("arraystack");
+#endif
 #endif
  ___Thread____NNR____staticStart____L___Thread___((struct ___Thread____NNR____staticStart____L___Thread____params *)p);
  objstrDelete(t_cache);