add native method for clearing prefetch cache to System.java
[IRC.git] / Robust / src / Runtime / DSTM / interface / objstr.c
index 4a66fa54565f9e81d87e310c58395f4dd6aec7a6..991bd239f7d68fbe198021b979dad508d85ddade 100644 (file)
@@ -1,11 +1,12 @@
 #include "dstm.h"
+extern objstr_t *prefetchcache;
 
-objstr_t *objstrCreate(unsigned int size)
-{
-       objstr_t *tmp = malloc(sizeof(objstr_t) + size);
-       tmp->size = size;
-       tmp->top = tmp + 1; //points to end of objstr_t structure!
-       return tmp;
+objstr_t *objstrCreate(unsigned int size) {
+  objstr_t *tmp = calloc(1, (sizeof(objstr_t) + size));
+  tmp->size = size;
+  tmp->next = NULL;
+  tmp->top = tmp + 1; //points to end of objstr_t structure!
+  return tmp;
 }
 
 //free entire list, starting at store
@@ -37,14 +38,19 @@ void *objstrAlloc(objstr_t *store, unsigned int size)
                {  //end of list, all full
                        if (size > DEFAULT_OBJ_STORE_SIZE) //in case of large objects
                        {
-                               store->next = (objstr_t *)malloc(sizeof(objstr_t) + size);
+                               store->next = (objstr_t *)calloc(1,(sizeof(objstr_t) + size));
+                               if (store->next == NULL)
+                                       return NULL;
                                store = store->next;
                                store->size = size;
                        }
                        else
                        {
-                               store->next = malloc(sizeof(objstr_t) + DEFAULT_OBJ_STORE_SIZE);
+                               store->next = calloc(1,(sizeof(objstr_t) + DEFAULT_OBJ_STORE_SIZE));
+                               if (store->next == NULL)
+                                       return NULL;
                                store = store->next;
+                               store->next = NULL;
                                store->size = DEFAULT_OBJ_STORE_SIZE;
                        }
                        store->top = (void *)((unsigned int)store + sizeof(objstr_t) + size);
@@ -55,3 +61,10 @@ void *objstrAlloc(objstr_t *store, unsigned int size)
        }
 }
 
+void clearObjStore() {
+  objstr_t *tmp = prefetchcache;
+  while(tmp != NULL) {
+    bzero(tmp+1, tmp->size);
+    tmp = tmp->next;
+  }
+}