From df64e4fa6637484d49b9727fd1aa8896bd92c54a Mon Sep 17 00:00:00 2001 From: stephey Date: Thu, 31 Mar 2011 02:28:21 +0000 Subject: [PATCH] Added manual invocation of garbage collector via System.gc() --- Robust/src/Runtime/garbage.h | 9 ++++++ Robust/src/Runtime/runtime.c | 57 ++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/Robust/src/Runtime/garbage.h b/Robust/src/Runtime/garbage.h index d8b56126..2290d972 100644 --- a/Robust/src/Runtime/garbage.h +++ b/Robust/src/Runtime/garbage.h @@ -9,6 +9,15 @@ struct garbagelist { void * array[]; }; +extern void * curr_heapbase; +extern void * curr_heapptr; +extern void * curr_heapgcpoint; +extern void * curr_heaptop; + +extern void * to_heapbase; +extern void * to_heapptr; +extern void * to_heaptop; + struct listitem { struct listitem * prev; struct listitem * next; diff --git a/Robust/src/Runtime/runtime.c b/Robust/src/Runtime/runtime.c index c6fd9a9b..c8b1ac5a 100644 --- a/Robust/src/Runtime/runtime.c +++ b/Robust/src/Runtime/runtime.c @@ -7,6 +7,11 @@ #include #include "option.h" #include "methodheaders.h" + +#if defined(THREADS)||defined(DSTM)||defined(STM)||defined(MLP) +#include "thread.h" +#endif + #ifdef DSTM #ifdef RECOVERY #include "DSTM/interface_recovery/dstm.h" @@ -59,6 +64,8 @@ pthread_barrierattr_t attr; #ifndef bool #define bool int #endif +#define GCPOINT(x) ((INTPTR)((x)*0.99)) + extern int classsize[]; extern int typearray[]; @@ -419,6 +426,56 @@ long long CALL00(___System______currentTimeMillis____) { return retval; } +void CALL00(___System______gc____) { +#if defined(THREADS)||defined(DSTM)||defined(STM)||defined(MLP) + while (pthread_mutex_trylock(&gclock)!=0) { + stopforgc((struct garbagelist *)___params___); + restartaftergc(); + } +#endif + + /* Grow the to heap if necessary */ + { + INTPTR curr_heapsize=curr_heaptop-curr_heapbase; + INTPTR to_heapsize=to_heaptop-to_heapbase; + + if (curr_heapsize>to_heapsize) { + free(to_heapbase); + to_heapbase=malloc(curr_heapsize); + if (to_heapbase==NULL) { + printf("Error Allocating enough memory\n"); + exit(-1); + } + to_heaptop=to_heapbase+curr_heapsize; + to_heapptr=to_heapbase; + } + } + + + collect((struct garbagelist *)___params___); + + { + void * tmp=to_heapbase; + to_heapbase=curr_heapbase; + curr_heapbase=tmp; + + tmp=to_heaptop; + to_heaptop=curr_heaptop; + curr_heaptop=tmp; + + tmp=to_heapptr; + curr_heapptr=to_heapptr; + curr_heapgcpoint=((char *) curr_heapbase)+GCPOINT(curr_heaptop-curr_heapbase); + to_heapptr=to_heapbase; + bzero(tmp, curr_heaptop-tmp); + + } + +#if defined(THREADS)||defined(DSTM)||defined(STM)||defined(MLP) + pthread_mutex_unlock(&gclock); +#endif +} + long long CALL00(___System______microTimes____) { struct timeval tv; long long retval; -- 2.34.1