From 3c51710b517f6f905d1f4b9c3cfbca9f2a34edbd Mon Sep 17 00:00:00 2001 From: adash Date: Mon, 14 Apr 2008 21:38:58 +0000 Subject: [PATCH] add native method for clearing prefetch cache to System.java --- Robust/src/Runtime/DSTM/interface/dstm.h | 2 ++ Robust/src/Runtime/DSTM/interface/objstr.c | 8 ++++++ Robust/src/Runtime/DSTM/interface/prelookup.c | 25 +++++++++++++++++++ Robust/src/Runtime/DSTM/interface/prelookup.h | 1 + Robust/src/Runtime/runtime.c | 8 ++++++ 5 files changed, 44 insertions(+) diff --git a/Robust/src/Runtime/DSTM/interface/dstm.h b/Robust/src/Runtime/DSTM/interface/dstm.h index 61c38a78..56cb9627 100644 --- a/Robust/src/Runtime/DSTM/interface/dstm.h +++ b/Robust/src/Runtime/DSTM/interface/dstm.h @@ -72,6 +72,7 @@ #include #include #include "sockpool.h" +#include "prelookup.h" //bit designations for status field of objheader #define DIRTY 0x01 @@ -226,6 +227,7 @@ unsigned int getNewOID(void); objstr_t *objstrCreate(unsigned int size); //size in bytes void objstrDelete(objstr_t *store); //traverse and free entire list void *objstrAlloc(objstr_t *store, unsigned int size); //size in bytes +void clearObjStore(); // TODO:currently only clears the prefetch cache object store /* end object store */ /* Prototypes for server portion */ diff --git a/Robust/src/Runtime/DSTM/interface/objstr.c b/Robust/src/Runtime/DSTM/interface/objstr.c index 2589deb8..991bd239 100644 --- a/Robust/src/Runtime/DSTM/interface/objstr.c +++ b/Robust/src/Runtime/DSTM/interface/objstr.c @@ -1,4 +1,5 @@ #include "dstm.h" +extern objstr_t *prefetchcache; objstr_t *objstrCreate(unsigned int size) { objstr_t *tmp = calloc(1, (sizeof(objstr_t) + size)); @@ -60,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; + } +} diff --git a/Robust/src/Runtime/DSTM/interface/prelookup.c b/Robust/src/Runtime/DSTM/interface/prelookup.c index 6eda49cf..4d596f1f 100644 --- a/Robust/src/Runtime/DSTM/interface/prelookup.c +++ b/Robust/src/Runtime/DSTM/interface/prelookup.c @@ -208,3 +208,28 @@ void prehashDelete() { free(ptr); } + +//Note: This is based on the implementation of the inserting a key in the first position of the hashtable +void prehashClear() { + int i, isFirstBin; + prehashlistnode_t *ptr, *prev, *curr; + + pthread_mutex_lock(&pflookup.lock); + ptr = pflookup.table; + for(i = 0; i < pflookup.size; i++) { + prev = &ptr[i]; + isFirstBin = 1; + while(prev->next != NULL) { + isFirstBin = 0; + curr = prev->next; + prev->next = curr->next; + free(curr); + } + if(isFirstBin == 1) { + prev->key = 0; + prev->next = NULL; + } + } + pthread_mutex_unlock(&pflookup.lock); +} + diff --git a/Robust/src/Runtime/DSTM/interface/prelookup.h b/Robust/src/Runtime/DSTM/interface/prelookup.h index df020b3b..ff74c65b 100644 --- a/Robust/src/Runtime/DSTM/interface/prelookup.h +++ b/Robust/src/Runtime/DSTM/interface/prelookup.h @@ -31,6 +31,7 @@ unsigned int prehashInsert(unsigned int key, void *val); void *prehashSearch(unsigned int key); //returns val, NULL if not found unsigned int prehashRemove(unsigned int key); //returns -1 if not found unsigned int prehashResize(unsigned int newsize); +void prehashClear(); /* end hash */ #endif diff --git a/Robust/src/Runtime/runtime.c b/Robust/src/Runtime/runtime.c index 197b9fb2..0bb81d2f 100644 --- a/Robust/src/Runtime/runtime.c +++ b/Robust/src/Runtime/runtime.c @@ -9,6 +9,7 @@ #include "option.h" #ifdef DSTM #include "dstm.h" +#include "prelookup.h" #endif extern int classsize[]; @@ -97,6 +98,13 @@ void CALL01(___System______printString____L___String___,struct ___String___ * __ } } +#ifdef DSTM +void CALL00(___System______clearPrefetchCache____) { + clearObjStore(); + prehashClear(); +} +#endif + /* Object allocation function */ #ifdef DSTM -- 2.34.1