Change the local hashtable for recording the pointer mapping info used in the gc...
authorjzhou <jzhou>
Thu, 8 Jul 2010 21:48:02 +0000 (21:48 +0000)
committerjzhou <jzhou>
Thu, 8 Jul 2010 21:48:02 +0000 (21:48 +0000)
Robust/src/Runtime/GCSharedHash.c
Robust/src/Runtime/MGCHash.c
Robust/src/Runtime/MGCHash.h
Robust/src/Runtime/multicoregarbage.c
Robust/src/Runtime/multicoregarbage.h
Robust/src/Runtime/multicoretask.c

index c6437ab18cb50cd086825797016431ea6a9b8001..98187f030efb8cb032c2e78d2a5cd4830b2ca5b4 100755 (executable)
@@ -170,7 +170,7 @@ struct GCSharedHash * allocateGCSharedHash_I(int size) {
   struct GCSharedHash *thisvar;
   if (size <= 0) {
 #ifdef MULTICORE
   struct GCSharedHash *thisvar;
   if (size <= 0) {
 #ifdef MULTICORE
-    BAMBOO_EXIT(0xf203);
+    BAMBOO_EXIT(0xf202);
 #else
     printf("Negative Hashtable size Exception\n");
     exit(-1);
 #else
     printf("Negative Hashtable size Exception\n");
     exit(-1);
@@ -291,14 +291,14 @@ mgcsharedhashtbl_t * mgcsharedhashCreate(unsigned int size,
   ctable = (mgcsharedhashtbl_t *)FREEMALLOC_NGC(sizeof(mgcsharedhashtbl_t));
   if(ctable == NULL) {
        // TODO
   ctable = (mgcsharedhashtbl_t *)FREEMALLOC_NGC(sizeof(mgcsharedhashtbl_t));
   if(ctable == NULL) {
        // TODO
-       BAMBOO_EXIT(0xeeee);
+       BAMBOO_EXIT(0xf203);
        return NULL;
   }
   // Allocate space for the hash table
   ctable->table = (mgcsharedhashlistnode_t *)FREEMALLOC_NGC(
          size*sizeof(mgcsharedhashlistnode_t));
   if(ctable->table == NULL) {
        return NULL;
   }
   // Allocate space for the hash table
   ctable->table = (mgcsharedhashlistnode_t *)FREEMALLOC_NGC(
          size*sizeof(mgcsharedhashlistnode_t));
   if(ctable->table == NULL) {
-       BAMBOO_EXIT(0xffff); // TODO
+       BAMBOO_EXIT(0xf204); // TODO
        return NULL;
   }
   ctable->size = size;
        return NULL;
   }
   ctable->size = size;
@@ -323,14 +323,14 @@ mgcsharedhashtbl_t * mgcsharedhashCreate_I(unsigned int size,
   ctable = (mgcsharedhashtbl_t *)FREEMALLOC_NGC_I(sizeof(mgcsharedhashtbl_t));
   if(ctable == NULL) {
        // TODO
   ctable = (mgcsharedhashtbl_t *)FREEMALLOC_NGC_I(sizeof(mgcsharedhashtbl_t));
   if(ctable == NULL) {
        // TODO
-       BAMBOO_EXIT(0xeeef);
+       BAMBOO_EXIT(0xf205);
        return NULL;
   }
   // Allocate space for the hash table
   ctable->table = (mgcsharedhashlistnode_t *)FREEMALLOC_NGC_I(
          size*sizeof(mgcsharedhashlistnode_t));
   if(ctable->table == NULL) {
        return NULL;
   }
   // Allocate space for the hash table
   ctable->table = (mgcsharedhashlistnode_t *)FREEMALLOC_NGC_I(
          size*sizeof(mgcsharedhashlistnode_t));
   if(ctable->table == NULL) {
-       BAMBOO_EXIT(0xfffe); // TODO
+       BAMBOO_EXIT(0xf206); // TODO
        return NULL;
   }
   ctable->size = size;
        return NULL;
   }
   ctable->size = size;
@@ -350,9 +350,9 @@ void mgcsharedhashReset(mgcsharedhashtbl_t * tbl) {
   mgcsharedhashlistnode_t * ptr = tbl->table;
 
   if ((tbl->numelements) < (tbl->size>>6)) {
   mgcsharedhashlistnode_t * ptr = tbl->table;
 
   if ((tbl->numelements) < (tbl->size>>6)) {
+       mgcsharedhashlistnode_t *top = &ptr[tbl->size];
        mgcsharedhashlistnode_t * list = tbl->list;
        mgcsharedhashlistnode_t * list = tbl->list;
-       while(list != NULL) {
-         mgcsharedhashlistnode_t *top = &ptr[tbl->size];
+       while(list != NULL) {  
       mgcsharedhashlistnode_t * next = list->next;
       if ((list >= ptr) && (list < top)) {
                //zero in list
       mgcsharedhashlistnode_t * next = list->next;
       if ((list >= ptr) && (list < top)) {
                //zero in list
index cb5569d42e970d4749b56a3432148c8b75e2bf08..5fe44056ba297325b95c04b99ea7ed1f90c48fb9 100755 (executable)
 #endif
 
 
 #endif
 
 
-/* MGCHASH ********************************************************/
-mgchashlistnode_t *mgc_table;
-unsigned int mgc_size;
-unsigned INTPTR mgc_mask;
-unsigned int mgc_numelements;
-unsigned int mgc_threshold;
-double mgc_loadfactor;
-mgcliststruct_t *mgc_structs;
-
-void mgchashCreate(unsigned int size, double loadfactor) {
+/* mgchash ********************************************************/
+mgchashtable_t * mgchashCreate(unsigned int size, double loadfactor) {
   mgchashtable_t *ctable;
   mgchashlistnode_t *nodes;
   int i;
 
   mgchashtable_t *ctable;
   mgchashlistnode_t *nodes;
   int i;
 
-  // Allocate space for the hash table
-  mgc_table = RUNMALLOC(size*sizeof(mgchashlistnode_t));
-  mgc_loadfactor = loadfactor;
-  mgc_size = size;
-  mgc_threshold=size*loadfactor;
-
-#ifdef BIT64
-  mgc_mask = ((size << 6)-1)&~(15UL);
+  if (size <= 0) {
+#ifdef MULTICORE
+    BAMBOO_EXIT(0xf101);
 #else
 #else
-  mgc_mask = ((size << 6)-1)&~15;
+    printf("Negative Hashtable size Exception\n");
+    exit(-1);
 #endif
 #endif
+  }
 
 
-  mgc_structs=RUNMALLOC(1*sizeof(mgcliststruct_t));
-  mgc_numelements = 0; // Initial number of elements in the hash
+  // Allocate space for the hash table
+  ctable = (mgchashtable_t *)RUNMALLOC(sizeof(mgchashtable_t));
+  if(ctable == NULL) {
+       // Run out of local memory
+       BAMBOO_EXIT(0xf102);
+  }
+  ctable->table = (mgchashlistnode_t*)RUNMALLOC(size*sizeof(mgchashlistnode_t));
+  if(ctable->table == NULL) {
+       // Run out of local memory
+       BAMBOO_EXIT(0xf103);
+  }
+  ctable->loadfactor = loadfactor;
+  ctable->size = size;
+  ctable->threshold=size*loadfactor;
+
+  ctable->mask = (size << 6)-1;
+  ctable->list = NULL;
+  ctable->structs = (mgcliststruct_t*)RUNMALLOC(1*sizeof(mgcliststruct_t));
+  ctable->numelements = 0; // Initial number of elements in the hash
+
+  return ctable;
 }
 
 }
 
-void mgchashreset() {
-  mgchashlistnode_t *ptr = mgc_table;
+void mgchashreset(mgchashtable_t * tbl) {
+  mgchashlistnode_t *ptr = tbl->table;
   int i;
 
   int i;
 
-  /*if (mgc_numelements<(mgc_size>>6)) {
-     mgchashlistnode_t *top=&ptr[mgc_size];
-     mgchashlistnode_t *tmpptr=mgc_list;
-     while(tmpptr!=NULL) {
-      mgchashlistnode_t *next=tmpptr->lnext;
-      if (tmpptr>=ptr&&tmpptr<top) {
-                                //zero in list
-                                tmpptr->key=NULL;
-                                tmpptr->next=NULL;
+  if (tbl->numelements<(tbl->size>>6)) {
+       mgchashlistnode_t *top=&ptr[tbl->size];
+       mgchashlistnode_t * list = tbl->list;
+       while(list != NULL) {
+      mgchashlistnode_t * next = list->next;
+      if ((list >= ptr) && (list < top)) {
+               //zero in list
+        list->key=NULL;
+        list->next=NULL;
       }
       }
-      tmpptr=next;
-     }
-     } else {*/
-  BAMBOO_MEMSET_WH(mgc_table, '\0', sizeof(mgchashlistnode_t)*mgc_size);
-  //}
-  while(mgc_structs->next!=NULL) {
-    mgcliststruct_t *next=mgc_structs->next;
-    RUNFREE(mgc_structs);
-    mgc_structs=next;
+      list = next;
+       }
+  } else {
+       BAMBOO_MEMSET_WH(tbl->table, '\0', sizeof(mgchashlistnode_t)*tbl->size);
+  }
+  // TODO now never release any allocated memory, may need to be changed
+  mgcliststruct_t * next = tbl->structs;
+  while(/*tbl->structs->*/next!=NULL) {
+    /*mgcliststruct_t * next = tbl->structs->next;
+    RUNFREE(tbl->structs);
+    tbl->structs=next;*/
+       next->num = 0;
+       next = next->next;
   }
   }
-  mgc_structs->num = 0;
-  mgc_numelements = 0;
+  //tbl->structs->num = 0;
+  tbl->numelements = 0;
 }
 
 //Store objects and their pointers into hash
 }
 
 //Store objects and their pointers into hash
-void mgchashInsert(void * key, void *val) {
+void mgchashInsert(mgchashtable_t * tbl, void * key, void *val) {
   mgchashlistnode_t *ptr;
 
   mgchashlistnode_t *ptr;
 
-  if(mgc_numelements > (mgc_threshold)) {
+  if(tbl->numelements > (tbl->threshold)) {
     //Resize
     //Resize
-    unsigned int newsize = mgc_size << 1 + 1;
-    mgchashResize(newsize);
+    unsigned int newsize = tbl->size << 1 + 1;
+    mgchashResize(tbl, newsize);
   }
 
   }
 
-  //int hashkey = (unsigned int)key % mgc_size;
-  ptr=&mgc_table[(((unsigned INTPTR)key)&mgc_mask)>>6]; //&mgc_table[hashkey];
-  mgc_numelements++;
+  ptr=&tbl->table[(((unsigned INTPTR)key)&tbl->mask)>>6]; 
+  tbl->numelements++;
 
   if(ptr->key==0) {
     // the first time insert a value for the key
 
   if(ptr->key==0) {
     // the first time insert a value for the key
@@ -97,14 +108,14 @@ void mgchashInsert(void * key, void *val) {
     ptr->val=val;
   } else { // Insert in the beginning of linked list
     mgchashlistnode_t * node;
     ptr->val=val;
   } else { // Insert in the beginning of linked list
     mgchashlistnode_t * node;
-    if (mgc_structs->num<NUMMGCLIST) {
-      node=&mgc_structs->array[mgc_structs->num];
-      mgc_structs->num++;
+    if (tbl->structs->num<NUMMGCLIST) {
+      node=&tbl->structs->array[tbl->structs->num];
+      tbl->structs->num++;
     } else {
       //get new list
       mgcliststruct_t *tcl=RUNMALLOC(1*sizeof(mgcliststruct_t));
     } else {
       //get new list
       mgcliststruct_t *tcl=RUNMALLOC(1*sizeof(mgcliststruct_t));
-      tcl->next=mgc_structs;
-      mgc_structs=tcl;
+      tcl->next=tbl->structs;
+      tbl->structs=tcl;
       node=&tcl->array[0];
       tcl->num=1;
     }
       node=&tcl->array[0];
       tcl->num=1;
     }
@@ -116,19 +127,54 @@ void mgchashInsert(void * key, void *val) {
 }
 
 #ifdef MULTICORE_GC
 }
 
 #ifdef MULTICORE_GC
-void mgchashInsert_I(void * key, void *val) {
+mgchashtable_t * mgchashCreate_I(unsigned int size, double loadfactor) {
+  mgchashtable_t *ctable;
+  mgchashlistnode_t *nodes;
+  int i;
+
+  if (size <= 0) {
+#ifdef MULTICORE
+    BAMBOO_EXIT(0xf101);
+#else
+    printf("Negative Hashtable size Exception\n");
+    exit(-1);
+#endif
+  }
+
+  // Allocate space for the hash table
+  ctable = (mgchashtable_t*)RUNMALLOC_I(sizeof(mgchashtable_t));
+  if(ctable == NULL) {
+       // Run out of local memory
+       BAMBOO_EXIT(0xf102);
+  }
+  ctable->table=(mgchashlistnode_t*)RUNMALLOC_I(size*sizeof(mgchashlistnode_t));
+  if(ctable->table == NULL) {
+       // Run out of local memory
+       BAMBOO_EXIT(0xf103);
+  }
+  ctable->loadfactor = loadfactor;
+  ctable->size = size;
+  ctable->threshold=size*loadfactor;
+
+  ctable->mask = (size << 6)-1;
+  ctable->list = NULL;
+  ctable->structs = (mgcliststruct_t*)RUNMALLOC_I(1*sizeof(mgcliststruct_t));
+  ctable->numelements = 0; // Initial number of elements in the hash
+
+  return ctable;
+}
+
+void mgchashInsert_I(mgchashtable_t * tbl, void * key, void *val) {
   mgchashlistnode_t *ptr;
 
   mgchashlistnode_t *ptr;
 
-  if(mgc_numelements > (mgc_threshold)) {
+  if(tbl->numelements > (tbl->threshold)) {
     //Resize
     //Resize
-    unsigned int newsize = mgc_size << 1 + 1;
-    mgchashResize_I(newsize);
+    unsigned int newsize = tbl->size << 1 + 1;
+    mgchashResize_I(tbl, newsize);
   }
 
   }
 
-  //int hashkey = (unsigned int)key % mgc_size;
-  //ptr=&mgc_table[hashkey];
-  ptr = &mgc_table[(((unsigned INTPTR)key)&mgc_mask)>>6];
-  mgc_numelements++;
+  ptr = &tbl->table[(((unsigned INTPTR)key)&tbl->mask)>>6];
+  tbl->numelements++;
 
   if(ptr->key==0) {
     ptr->key=key;
 
   if(ptr->key==0) {
     ptr->key=key;
@@ -136,14 +182,14 @@ void mgchashInsert_I(void * key, void *val) {
     return;
   } else { // Insert in the beginning of linked list
     mgchashlistnode_t * node;
     return;
   } else { // Insert in the beginning of linked list
     mgchashlistnode_t * node;
-    if (mgc_structs->num<NUMMGCLIST) {
-      node=&mgc_structs->array[mgc_structs->num];
-      mgc_structs->num++;
+    if (tbl->structs->num<NUMMGCLIST) {
+      node=&tbl->structs->array[tbl->structs->num];
+      tbl->structs->num++;
     } else {
       //get new list
       mgcliststruct_t *tcl=RUNMALLOC_I(1*sizeof(mgcliststruct_t));
     } else {
       //get new list
       mgcliststruct_t *tcl=RUNMALLOC_I(1*sizeof(mgcliststruct_t));
-      tcl->next=mgc_structs;
-      mgc_structs=tcl;
+      tcl->next=tbl->structs;
+      tbl->structs=tcl;
       node=&tcl->array[0];
       tcl->num=1;
     }
       node=&tcl->array[0];
       tcl->num=1;
     }
@@ -156,11 +202,9 @@ void mgchashInsert_I(void * key, void *val) {
 #endif
 
 // Search for an address for a given oid
 #endif
 
 // Search for an address for a given oid
-INLINE void * mgchashSearch(void * key) {
+INLINE void * mgchashSearch(mgchashtable_t * tbl, void * key) {
   //REMOVE HASH FUNCTION CALL TO MAKE SURE IT IS INLINED HERE]
   //REMOVE HASH FUNCTION CALL TO MAKE SURE IT IS INLINED HERE]
-  //int hashkey = (unsigned int)key % mgc_size;
-  mgchashlistnode_t *node = &mgc_table[(((unsigned INTPTR)key)&mgc_mask)>>6];
-  //&mgc_table[hashkey];
+  mgchashlistnode_t *node = &tbl->table[(((unsigned INTPTR)key)&tbl->mask)>>6];
 
   do {
     if(node->key == key) {
 
   do {
     if(node->key == key) {
@@ -172,57 +216,61 @@ INLINE void * mgchashSearch(void * key) {
   return NULL;
 }
 
   return NULL;
 }
 
-unsigned int mgchashResize(unsigned int newsize) {
-  mgchashlistnode_t *node, *ptr, *curr;    // curr and next keep track of the current and the next mgchashlistnodes in a linked list
+unsigned int mgchashResize(mgchashtable_t * tbl, unsigned int newsize) {
+  mgchashlistnode_t *node, *ptr, *curr;  // curr and next keep track of the 
+                                         // current and the next 
+                                                                                // mgchashlistnodes in a linked list
   unsigned int oldsize;
   unsigned int oldsize;
-  int isfirst;    // Keeps track of the first element in the chashlistnode_t for each bin in hashtable
+  int isfirst;    // Keeps track of the first element in the 
+                  // chashlistnode_t for each bin in hashtable
   unsigned int i,index;
   unsigned int mask;
 
   unsigned int i,index;
   unsigned int mask;
 
-  ptr = mgc_table;
-  oldsize = mgc_size;
+  ptr = tbl->table;
+  oldsize = tbl->size;
 
   if((node = RUNMALLOC(newsize*sizeof(mgchashlistnode_t))) == NULL) {
     printf("Calloc error %s %d\n", __FILE__, __LINE__);
     return 1;
   }
 
 
   if((node = RUNMALLOC(newsize*sizeof(mgchashlistnode_t))) == NULL) {
     printf("Calloc error %s %d\n", __FILE__, __LINE__);
     return 1;
   }
 
-  mgc_table = node;          //Update the global hashtable upon resize()
-  mgc_size = newsize;
-  mgc_threshold = newsize * mgc_loadfactor;
-  mask=mgc_mask = (newsize << 6)-1;
+  tbl->table = node; //Update the global hashtable upon resize()
+  tbl->size = newsize;
+  tbl->threshold = newsize * tbl->loadfactor;
+  mask = tbl->mask = (newsize << 6) - 1;
 
 
-  for(i = 0; i < oldsize; i++) {                        //Outer loop for each bin in hash table
+  for(i = 0; i < oldsize; i++) {   //Outer loop for each bin in hash table
     curr = &ptr[i];
     isfirst = 1;
     curr = &ptr[i];
     isfirst = 1;
-    do {                      //Inner loop to go through linked lists
+    do {  //Inner loop to go through linked lists
       void * key;
       mgchashlistnode_t *tmp,*next;
 
       void * key;
       mgchashlistnode_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
-      }
-      //index = (unsigned int)key % mgc_size;
-      index = (((unsigned INTPTR)key) & mask) >>6;
+      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
+         }
+      index = (((unsigned INTPTR)key) & mask) >> 6;
       tmp=&node[index];
       next = curr->next;
       // Insert into the new table
       if(tmp->key == 0) {
       tmp=&node[index];
       next = curr->next;
       // Insert into the new table
       if(tmp->key == 0) {
-       tmp->key = key;
-       tmp->val = curr->val;
+               tmp->key = key;
+               tmp->val = curr->val;
       } /*
           NOTE:  Add this case if you change this...
       } /*
           NOTE:  Add this case if you change this...
-          This case currently never happens because of the way things rehash....
+          This case currently never happens because of the way things rehash....*/
           else if (isfirst) {
           else if (isfirst) {
-          chashlistnode_t *newnode= calloc(1, sizeof(chashlistnode_t));
-          newnode->key = curr->key;
-          newnode->val = curr->val;
-          newnode->next = tmp->next;
-          tmp->next=newnode;
-          } */
+                mgchashlistnode_t *newnode= RUNMALLOC(1*sizeof(mgchashlistnode_t));
+                newnode->key = curr->key;
+                newnode->val = curr->val;
+                newnode->next = tmp->next;
+                tmp->next=newnode;
+          } 
       else {
       else {
-       curr->next=tmp->next;
-       tmp->next=curr;
+               curr->next=tmp->next;
+               tmp->next=curr;
       }
 
       isfirst = 0;
       }
 
       isfirst = 0;
@@ -235,90 +283,94 @@ unsigned int mgchashResize(unsigned int newsize) {
 }
 
 #ifdef MULTICORE_GC
 }
 
 #ifdef MULTICORE_GC
-unsigned int mgchashResize_I(unsigned int newsize) {
-  mgchashlistnode_t *node, *ptr, *curr;    // curr and next keep track of the current and the next mgchashlistnodes in a linked list
+unsigned int mgchashResize_I(mgchashtable_t * tbl, unsigned int newsize) {
+  mgchashlistnode_t *node, *ptr, *curr; // curr and next keep track of the 
+                                        // current and the next 
+                                                                               // mgchashlistnodes in a linked list
   unsigned int oldsize;
   unsigned int oldsize;
-  int isfirst;    // Keeps track of the first element in the chashlistnode_t for each bin in hashtable
+  int isfirst; // Keeps track of the first element in the chashlistnode_t 
+               // for each bin in hashtable
   unsigned int i,index;
   unsigned int mask;
 
   unsigned int i,index;
   unsigned int mask;
 
-  ptr = mgc_table;
-  oldsize = mgc_size;
+  ptr = tbl->table;
+  oldsize = tbl->size;
 
   if((node = RUNMALLOC_I(newsize*sizeof(mgchashlistnode_t))) == NULL) {
 
   if((node = RUNMALLOC_I(newsize*sizeof(mgchashlistnode_t))) == NULL) {
-    BAMBOO_EXIT(0xe001);
+    BAMBOO_EXIT(0xf104);
     printf("Calloc error %s %d\n", __FILE__, __LINE__);
     return 1;
   }
 
     printf("Calloc error %s %d\n", __FILE__, __LINE__);
     return 1;
   }
 
-  mgc_table = node;          //Update the global hashtable upon resize()
-  mgc_size = newsize;
-  mgc_threshold = newsize * mgc_loadfactor;
-  mask=mgc_mask = (newsize << 6)-1;
+  tbl->table = node;  //Update the global hashtable upon resize()
+  tbl->size = newsize;
+  tbl->threshold = newsize * tbl->loadfactor;
+  mask = tbl->mask = (newsize << 6)-1;
 
 
-  for(i = 0; i < oldsize; i++) {                        //Outer loop for each bin in hash table
+  for(i = 0; i < oldsize; i++) {  //Outer loop for each bin in hash table
     curr = &ptr[i];
     isfirst = 1;
     curr = &ptr[i];
     isfirst = 1;
-    do {                      //Inner loop to go through linked lists
+    do { //Inner loop to go through linked lists
       void * key;
       mgchashlistnode_t *tmp,*next;
 
       if ((key=curr->key) == 0) {
       void * key;
       mgchashlistnode_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
+               //Exit inner loop if there the first element is 0
+               break;
+               //key = val =0 for element if not present within the hash table
       }
       }
-      //index = (unsigned int)key % mgc_size;
       index = (((unsigned INTPTR)key) & mask) >>6;
       tmp=&node[index];
       next = curr->next;
       // Insert into the new table
       if(tmp->key == 0) {
       index = (((unsigned INTPTR)key) & mask) >>6;
       tmp=&node[index];
       next = curr->next;
       // Insert into the new table
       if(tmp->key == 0) {
-       tmp->key = key;
-       tmp->val = curr->val;
+               tmp->key = key;
+               tmp->val = curr->val;
       } /*
           NOTE:  Add this case if you change this...
           This case currently never happens because of the way things rehash....*/
       else if (isfirst) {
       } /*
           NOTE:  Add this case if you change this...
           This case currently never happens because of the way things rehash....*/
       else if (isfirst) {
-       mgchashlistnode_t *newnode=RUNMALLOC_I(1*sizeof(mgchashlistnode_t));
-       newnode->key = curr->key;
-       newnode->val = curr->val;
-       newnode->next = tmp->next;
-       tmp->next=newnode;
+               mgchashlistnode_t *newnode=RUNMALLOC_I(1*sizeof(mgchashlistnode_t)); 
+               newnode->key = curr->key;
+               newnode->val = curr->val;
+               newnode->next = tmp->next;
+               tmp->next=newnode;
       } else {
       } else {
-       curr->next=tmp->next;
-       tmp->next=curr;
+               curr->next=tmp->next;
+               tmp->next=curr;
       }
 
       isfirst = 0;
       curr = next;
     } while(curr!=NULL);
   }
       }
 
       isfirst = 0;
       curr = next;
     } while(curr!=NULL);
   }
-  RUNFREE(ptr);            //Free the memory of the old hash table
+  RUNFREE(ptr); //Free the memory of the old hash table
   return 0;
 }
 #endif
 
 //Delete the entire hash table
   return 0;
 }
 #endif
 
 //Delete the entire hash table
-void mgchashDelete() {
+void mgchashDelete(mgchashtable_t * tbl) {
   int i;
   int i;
-  mgcliststruct_t *ptr=mgc_structs;
+  mgcliststruct_t *ptr=tbl->structs;
   while(ptr!=NULL) {
     mgcliststruct_t *next=ptr->next;
     RUNFREE(ptr);
     ptr=next;
   }
   while(ptr!=NULL) {
     mgcliststruct_t *next=ptr->next;
     RUNFREE(ptr);
     ptr=next;
   }
-  RUNFREE(mgc_table);
-  mgc_table=NULL;
-  mgc_structs=NULL;
+  RUNFREE(tbl->table);
+  tbl->table=NULL;
+  tbl->structs=NULL;
 }
 
 }
 
+/* MGCHASH ********************************************************/
+
 struct MGCHash * allocateMGCHash(int size,
                                  int conflicts) {
   struct MGCHash *thisvar;
   if (size <= 0) {
 #ifdef MULTICORE
 struct MGCHash * allocateMGCHash(int size,
                                  int conflicts) {
   struct MGCHash *thisvar;
   if (size <= 0) {
 #ifdef MULTICORE
-    BAMBOO_EXIT(0xf101);
+    BAMBOO_EXIT(0xf105);
 #else
     printf("Negative Hashtable size Exception\n");
     exit(-1);
 #else
     printf("Negative Hashtable size Exception\n");
     exit(-1);
@@ -382,7 +434,7 @@ struct MGCHash * allocateMGCHash_I(int size,
   struct MGCHash *thisvar;
   if (size <= 0) {
 #ifdef MULTICORE
   struct MGCHash *thisvar;
   if (size <= 0) {
 #ifdef MULTICORE
-    BAMBOO_EXIT(0xf101);
+    BAMBOO_EXIT(0xf106);
 #else
     printf("Negative Hashtable size Exception\n");
     exit(-1);
 #else
     printf("Negative Hashtable size Exception\n");
     exit(-1);
index 9a855145dd3dac7a05d51996c42e7aa6ad26aec1..6c0459d53b3534ff2acec8be035c738f8752f78d 100755 (executable)
@@ -19,7 +19,7 @@
 
 #include "mem.h"
 
 
 #include "mem.h"
 
-/* MGCHash *********************************************************/
+/* mgchash *********************************************************/
 typedef struct mgchashlistnode {
   void * key;
   void * val; //this can be cast to another type or used to point to a
 typedef struct mgchashlistnode {
   void * key;
   void * val; //this can be cast to another type or used to point to a
@@ -27,8 +27,17 @@ typedef struct mgchashlistnode {
   struct mgchashlistnode *next;
 } mgchashlistnode_t;
 
   struct mgchashlistnode *next;
 } mgchashlistnode_t;
 
+#define NUMMGCLIST 250
+typedef struct mgclist {
+  struct mgchashlistnode array[NUMMGCLIST];
+  int num;
+  struct mgclist *next;
+} mgcliststruct_t;
+
 typedef struct mgchashtable {
 typedef struct mgchashtable {
-  mgchashlistnode_t *table;       // points to beginning of hash table
+  mgchashlistnode_t * table;       // points to beginning of hash table
+  mgchashlistnode_t * list;
+  mgcliststruct_t * structs;
   unsigned int size;
   unsigned int mask;
   unsigned int numelements;
   unsigned int size;
   unsigned int mask;
   unsigned int numelements;
@@ -36,25 +45,20 @@ typedef struct mgchashtable {
   double loadfactor;
 } mgchashtable_t;
 
   double loadfactor;
 } mgchashtable_t;
 
-#define NUMMGCLIST 250
-typedef struct mgclist {
-  struct mgchashlistnode array[NUMMGCLIST];
-  int num;
-  struct mgclist *next;
-} mgcliststruct_t;
-
-void mgchashCreate(unsigned int size, double loadfactor);
-void mgchashInsert(void * key, void *val);
-void * mgchashSearch(void * key);
-unsigned int mgchashResize(unsigned int newsize);
+mgchashtable_t * mgchashCreate(unsigned int size, double loadfactor);
+void mgchashInsert(mgchashtable_t * tbl, void * key, void *val);
+void * mgchashSearch(mgchashtable_t * tbl, void * key);
+unsigned int mgchashResize(mgchashtable_t * tbl, unsigned int newsize);
 #ifdef MULTICORE_GC
 #ifdef MULTICORE_GC
-void mgchashInsert_I(void * key, void *val);
-unsigned int mgchashResize_I(unsigned int newsize);
+mgchashtable_t * mgchashCreate_I(unsigned int size, double loadfactor);
+void mgchashInsert_I(mgchashtable_t * tbl, void * key, void *val);
+unsigned int mgchashResize_I(mgchashtable_t * tbl, unsigned int newsize);
 #endif
 #endif
-void mgchashDelete();
-void mgchashreset();
+void mgchashDelete(mgchashtable_t * tbl);
+void mgchashreset(mgchashtable_t * tbl);
 
 
 
 
+/** MGCHash *******************************************************************/
 struct MGCHash * allocateMGCHash(int size, int conflicts);
 void freeMGCHash(struct MGCHash *);
 
 struct MGCHash * allocateMGCHash(int size, int conflicts);
 void freeMGCHash(struct MGCHash *);
 
index cf37a5e49b8dc2ecd52e9c4e8ac5d14383e3166c..5efb32a8f3bfdbb2eddebd327729d59fa2b7931a 100644 (file)
@@ -634,10 +634,13 @@ inline void initGC() {
   }
   gclobjhead->next = gclobjhead->prev = NULL;
 
   }
   gclobjhead->next = gclobjhead->prev = NULL;
 
+#ifdef LOCALHASHTBL_TEST
   freeRuntimeHash(gcpointertbl);
   gcpointertbl = allocateRuntimeHash(20);
   freeRuntimeHash(gcpointertbl);
   gcpointertbl = allocateRuntimeHash(20);
+#else
+  mgchashreset(gcpointertbl);
+#endif
   //gcpointertbl = allocateMGCHash(20);
   //gcpointertbl = allocateMGCHash(20);
-  //mgchashreset();
 
   freeMGCHash(gcforwardobjtbl);
   gcforwardobjtbl = allocateMGCHash(20, 3);
 
   freeMGCHash(gcforwardobjtbl);
   gcforwardobjtbl = allocateMGCHash(20, 3);
@@ -982,8 +985,6 @@ inline void moveLObjs() {
                }
                // fill the remaining space with -2 padding
                BAMBOO_MEMSET_WH(tmpheaptop+size, -2, isize-size);
                }
                // fill the remaining space with -2 padding
                BAMBOO_MEMSET_WH(tmpheaptop+size, -2, isize-size);
-               // zero out original mem caching the lobj
-               //BAMBOO_MEMSET_WH(gcheaptop, '\0', size); // TODO ??
 #ifdef DEBUG
                BAMBOO_DEBUGPRINT(0xea05);
                BAMBOO_DEBUGPRINT_REG(gcheaptop);
 #ifdef DEBUG
                BAMBOO_DEBUGPRINT(0xea05);
                BAMBOO_DEBUGPRINT_REG(gcheaptop);
@@ -996,11 +997,11 @@ inline void moveLObjs() {
                // cache the mapping info anyway
                //if(ptr != tmpheaptop) {
                BAMBOO_ENTER_RUNTIME_MODE_FROM_CLIENT();
                // cache the mapping info anyway
                //if(ptr != tmpheaptop) {
                BAMBOO_ENTER_RUNTIME_MODE_FROM_CLIENT();
-               //mgchashInsert_I(ptr, tmpheaptop);
+#ifdef LOCALHASHTBL_TEST
                RuntimeHashadd_I(gcpointertbl, ptr, tmpheaptop);
                RuntimeHashadd_I(gcpointertbl, ptr, tmpheaptop);
-               //struct nodemappinginfo * nodeinfo = NULL;
-               //RuntimeHashget(gcpointertbl, ptr, &nodeinfo);
-               //nodeinfo->ptr = tmpheaptop;
+#else
+               mgchashInsert_I(gcpointertbl, ptr, tmpheaptop);
+#endif
                //MGCHashadd_I(gcpointertbl, ptr, tmpheaptop);
                BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
                //}
                //MGCHashadd_I(gcpointertbl, ptr, tmpheaptop);
                BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
                //}
@@ -1083,11 +1084,11 @@ inline void moveLObjs() {
                // cache the mapping info anyway
                //if(ptr != tmpheaptop) {
                BAMBOO_ENTER_RUNTIME_MODE_FROM_CLIENT();
                // cache the mapping info anyway
                //if(ptr != tmpheaptop) {
                BAMBOO_ENTER_RUNTIME_MODE_FROM_CLIENT();
-               //mgchashInsert_I(ptr, tmpheaptop);
+#ifdef LOCALHASHTBL_TEST
                RuntimeHashadd_I(gcpointertbl, ptr, tmpheaptop);
                RuntimeHashadd_I(gcpointertbl, ptr, tmpheaptop);
-               //struct nodemappinginfo * nodeinfo = NULL;
-               //RuntimeHashget(gcpointertbl, ptr, &nodeinfo);
-               //nodeinfo->ptr = tmpheaptop;
+#else
+               mgchashInsert_I(gcpointertbl, ptr, tmpheaptop);
+#endif
                //MGCHashadd_I(gcpointertbl, ptr, tmpheaptop);
                BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
                //}
                //MGCHashadd_I(gcpointertbl, ptr, tmpheaptop);
                BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
                //}
@@ -1963,8 +1964,12 @@ innermoveobj:
     }
     // store mapping info
     BAMBOO_ENTER_RUNTIME_MODE_FROM_CLIENT();
     }
     // store mapping info
     BAMBOO_ENTER_RUNTIME_MODE_FROM_CLIENT();
-    //mgchashInsert_I(orig->ptr, to->ptr);
+#ifdef LOCALHASHTBL_TEST
     RuntimeHashadd_I(gcpointertbl, orig->ptr, to->ptr);
     RuntimeHashadd_I(gcpointertbl, orig->ptr, to->ptr);
+#else
+       mgchashInsert_I(gcpointertbl, orig->ptr, to->ptr);
+#endif
+       //MGCHashadd_I(gcpointertbl, orig->ptr, to->ptr);
        if(isremote) {
 #ifdef GC_PROFILE
        //unsigned long long ttimet = BAMBOO_GET_EXE_TIME();
        if(isremote) {
 #ifdef GC_PROFILE
        //unsigned long long ttimet = BAMBOO_GET_EXE_TIME();
@@ -1979,7 +1984,6 @@ innermoveobj:
        //flushstalltime_i += BAMBOO_GET_EXE_TIME()-ttimet;
 #endif
        }
        //flushstalltime_i += BAMBOO_GET_EXE_TIME()-ttimet;
 #endif
        }
-    //MGCHashadd_I(gcpointertbl, orig->ptr, to->ptr);
     BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
     //}
 #ifdef DEBUG
     BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
     //}
 #ifdef DEBUG
@@ -2267,12 +2271,15 @@ inline void * flushObj(void * objptr) {
 #ifdef GC_PROFILE
     unsigned long long ttime = BAMBOO_GET_EXE_TIME();
 #endif
 #ifdef GC_PROFILE
     unsigned long long ttime = BAMBOO_GET_EXE_TIME();
 #endif
-    //dstptr = mgchashSearch(objptr);
+#ifdef LOCALHASHTBL_TEST
     RuntimeHashget(gcpointertbl, objptr, &dstptr);
     RuntimeHashget(gcpointertbl, objptr, &dstptr);
+#else
+       dstptr = mgchashSearch(gcpointertbl, objptr);
+#endif
+       //MGCHashget(gcpointertbl, objptr, &dstptr);
 #ifdef GC_PROFILE
     flushstalltime += BAMBOO_GET_EXE_TIME()-ttime;
 #endif
 #ifdef GC_PROFILE
     flushstalltime += BAMBOO_GET_EXE_TIME()-ttime;
 #endif
-    //MGCHashget(gcpointertbl, objptr, &dstptr);
     BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
 #ifdef DEBUG
     BAMBOO_DEBUGPRINT_REG(dstptr);
     BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
 #ifdef DEBUG
     BAMBOO_DEBUGPRINT_REG(dstptr);
@@ -2304,7 +2311,11 @@ inline void * flushObj(void * objptr) {
                  //GCSharedHashget(sptbl, (int)objptr, &dstptr);
                  dstptr = mgcsharedhashSearch(sptbl, (int)objptr);
                  if(dstptr != NULL) {
                  //GCSharedHashget(sptbl, (int)objptr, &dstptr);
                  dstptr = mgcsharedhashSearch(sptbl, (int)objptr);
                  if(dstptr != NULL) {
+#ifdef LOCALHASHTBL_TEST
                        RuntimeHashadd_I(gcpointertbl, (int)objptr, (int)dstptr);
                        RuntimeHashadd_I(gcpointertbl, (int)objptr, (int)dstptr);
+#else
+                       mgchashInsert_I(gcpointertbl, (int)objptr, (int)dstptr);
+#endif
                  }
                }
                BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
                  }
                }
                BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
@@ -2343,8 +2354,11 @@ inline void * flushObj(void * objptr) {
                  //flushstalltime += BAMBOO_GET_EXE_TIME() - ttime;
 #endif
                  BAMBOO_ENTER_RUNTIME_MODE_FROM_CLIENT();
                  //flushstalltime += BAMBOO_GET_EXE_TIME() - ttime;
 #endif
                  BAMBOO_ENTER_RUNTIME_MODE_FROM_CLIENT();
-                 //dstptr = mgchashSearch(objptr);
+#ifdef LOCALHASHTBL_TEST
                  RuntimeHashget(gcpointertbl, objptr, &dstptr);
                  RuntimeHashget(gcpointertbl, objptr, &dstptr);
+#else
+                 dstptr = mgchashSearch(gcpointertbl, objptr);
+#endif
                  //MGCHashget(gcpointertbl, objptr, &dstptr);
                  BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
                } // if(dstptr == NULL)
                  //MGCHashget(gcpointertbl, objptr, &dstptr);
                  BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
                } // if(dstptr == NULL)
index 997a646b52fd73a15a89699cf4dc7111f9db6581..6d16cfbf5dbbcfcca399de5ab6e12d3dd18a2e5e 100644 (file)
@@ -124,7 +124,11 @@ mgcsharedhashtbl_t * gcsharedptbl;
 //struct GCSharedHash * gcrpointertbls[NUMCORES4GC];
 mgcsharedhashtbl_t * gcrpointertbls[NUMCORES4GC];
 
 //struct GCSharedHash * gcrpointertbls[NUMCORES4GC];
 mgcsharedhashtbl_t * gcrpointertbls[NUMCORES4GC];
 
-volatile struct RuntimeHash * gcpointertbl;
+#ifdef LOCALHASHTBL_TEST
+struct RuntimeHash * gcpointertbl;
+#else
+mgchashtable_t * gcpointertbl;
+#endif
 //struct MGCHash * gcpointertbl;
 int gcobj2map;
 int gcmappedobj;
 //struct MGCHash * gcpointertbl;
 int gcobj2map;
 int gcmappedobj;
index 35ba9e3dab6379e8579c5859d424718541d6b566..9c1cecaf6fdaf37d6f363c086b05e7ba2f4de375 100644 (file)
@@ -259,9 +259,12 @@ void initruntimedata() {
   gcself_numsendobjs = 0;
   gcself_numreceiveobjs = 0;
   gcmarkedptrbound = 0;
   gcself_numsendobjs = 0;
   gcself_numreceiveobjs = 0;
   gcmarkedptrbound = 0;
-  //mgchashCreate(2000, 0.75);
+#ifdef LOCALHASHTBL_TEST
   gcpointertbl = allocateRuntimeHash_I(20);
   gcpointertbl = allocateRuntimeHash_I(20);
-  //gcpointertbl = allocateMGCHash(20);
+#else
+  gcpointertbl = mgchashCreate_I(2000, 0.75);
+#endif
+  //gcpointertbl = allocateMGCHash_I(20);
   gcforwardobjtbl = allocateMGCHash_I(20, 3);
   gcobj2map = 0;
   gcmappedobj = 0;
   gcforwardobjtbl = allocateMGCHash_I(20, 3);
   gcobj2map = 0;
   gcmappedobj = 0;
@@ -345,8 +348,11 @@ void initruntimedata() {
 inline __attribute__((always_inline))
 void disruntimedata() {
 #ifdef MULTICORE_GC
 inline __attribute__((always_inline))
 void disruntimedata() {
 #ifdef MULTICORE_GC
-  //mgchashDelete();
+#ifdef LOCALHASHTBL_TEST
   freeRuntimeHash(gcpointertbl);
   freeRuntimeHash(gcpointertbl);
+#else
+  mgchashDelete(gcpointertbl);
+#endif
   //freeMGCHash(gcpointertbl);
   freeMGCHash(gcforwardobjtbl);
   // for mapping info structures
   //freeMGCHash(gcpointertbl);
   freeMGCHash(gcforwardobjtbl);
   // for mapping info structures
@@ -2740,17 +2746,20 @@ INLINE void processmsg_gcmaprequest_I() {
   void * dstptr = NULL;
   int data1 = msgdata[msgdataindex];
   MSG_INDEXINC_I();
   void * dstptr = NULL;
   int data1 = msgdata[msgdataindex];
   MSG_INDEXINC_I();
-  //dstptr = mgchashSearch(msgdata[1]);
 #ifdef GC_PROFILE
   // TODO unsigned long long ttime = BAMBOO_GET_EXE_TIME();
 #endif
 #ifdef GC_PROFILE
   // TODO unsigned long long ttime = BAMBOO_GET_EXE_TIME();
 #endif
+#ifdef LOCALHASHTBL_TEST
   RuntimeHashget(gcpointertbl, data1, &dstptr);
   RuntimeHashget(gcpointertbl, data1, &dstptr);
+#else
+  dstptr = mgchashSearch(gcpointertbl, data1);
+#endif
+  //MGCHashget(gcpointertbl, data1, &dstptr);
 #ifdef GC_PROFILE
   // TODO flushstalltime += BAMBOO_GET_EXE_TIME() - ttime;
 #endif
   int data2 = msgdata[msgdataindex];
   MSG_INDEXINC_I();
 #ifdef GC_PROFILE
   // TODO flushstalltime += BAMBOO_GET_EXE_TIME() - ttime;
 #endif
   int data2 = msgdata[msgdataindex];
   MSG_INDEXINC_I();
-  //MGCHashget(gcpointertbl, msgdata[1], &dstptr);
 #ifdef GC_PROFILE
   // TODO unsigned long long ttimei = BAMBOO_GET_EXE_TIME();
 #endif
 #ifdef GC_PROFILE
   // TODO unsigned long long ttimei = BAMBOO_GET_EXE_TIME();
 #endif
@@ -2787,17 +2796,14 @@ INLINE void processmsg_gcmapinfo_I() {
 #endif
   int data1 = msgdata[msgdataindex];
   MSG_INDEXINC_I();
 #endif
   int data1 = msgdata[msgdataindex];
   MSG_INDEXINC_I();
-    gcmappedobj = msgdata[msgdataindex];  // [2]
-    MSG_INDEXINC_I();
-    //mgchashReplace_I(msgdata[1], msgdata[2]);
-    //mgchashInsert_I(gcobj2map, gcmappedobj);
-    RuntimeHashadd_I(gcpointertbl, gcobj2map, gcmappedobj);
-       /*struct nodemappinginfo * nodeinfo = 
-        (struct nodemappinginfo *)RUNMALLOC_I(sizeof(struct nodemappinginfo));
-       nodeinfo->ptr = (void *)gcmappedobj;
-       nodeinfo->cores = NULL;
-       RuntimeHashadd_I(gcpointertbl, data1, (int)nodeinfo);*/
-    //MGCHashadd_I(gcpointertbl, gcobj2map, gcmappedobj);
+  gcmappedobj = msgdata[msgdataindex];  // [2]
+  MSG_INDEXINC_I();
+#ifdef LOCALHASHTBL_TEST
+  RuntimeHashadd_I(gcpointertbl, data1, gcmappedobj);
+#else
+  mgchashInsert_I(gcpointertbl, data1, gcmappedobj);
+#endif
+  //MGCHashadd_I(gcpointertbl, data1, gcmappedobj);
   if(data1 == gcobj2map) {
        gcismapped = true;
   }
   if(data1 == gcobj2map) {
        gcismapped = true;
   }
@@ -2852,11 +2858,13 @@ INLINE void processmsg_gclobjmapping_I() {
   MSG_INDEXINC_I();
   int data2 = msgdata[msgdataindex];
   MSG_INDEXINC_I();
   MSG_INDEXINC_I();
   int data2 = msgdata[msgdataindex];
   MSG_INDEXINC_I();
-  //mgchashInsert_I(msgdata[1], msgdata[2]);
+#ifdef LOCALHASHTBL_TEST
   RuntimeHashadd_I(gcpointertbl, data1, data2);
   RuntimeHashadd_I(gcpointertbl, data1, data2);
+#else
+  mgchashInsert_I(gcpointertbl, data1, data2);
+#endif
+  //MGCHashadd_I(gcpointertbl, data1, data2);
   mgcsharedhashInsert_I(gcsharedptbl, data1, data2);
   mgcsharedhashInsert_I(gcsharedptbl, data1, data2);
-  //GCSharedHashadd_I(gcsharedptbl, data1, data2);
-  //MGCHashadd_I(gcpointertbl, msgdata[1], msgdata[2]);
 }
 #endif // #ifdef MULTICORE_GC
 
 }
 #endif // #ifdef MULTICORE_GC