commit a0e33a2cb5c8b9eee69edff6346817a17249c29a
parent 3abe4c413192db697ecf8fc6dc1cdaef534546b0
Author: Andres Navarro <canavarro82@gmail.com>
Date: Sat, 16 Apr 2011 17:55:02 -0300
GC implementation complete. Bugs pending.
Diffstat:
5 files changed, 27 insertions(+), 4 deletions(-)
diff --git a/src/Makefile b/src/Makefile
@@ -60,7 +60,7 @@ kstate.o: kstate.c kstate.h klisp.h kobject.h kmem.h kstring.h klisp.h \
kground.h kenvironment.h kpair.h keval.h koperative.h kground.h \
krepl.h kcontinuation.h kapplicative.h kport.h ksymbol.h kport.h \
kstring.h kinteger.h kgc.h
-kmem.o: kmem.c kmem.h klisp.h kerror.h klisp.h kstate.h
+kmem.o: kmem.c kmem.h klisp.h kerror.h klisp.h kstate.h kgc.h
kerror.o: kerror.c kerror.h klisp.h kstate.h klisp.h kmem.h kstring.h kpair.h
kauxlib.o: kauxlib.c kauxlib.h klisp.h kstate.h klisp.h
kenvironment.o: kenvironment.c kenvironment.h kpair.h kobject.h kerror.h \
diff --git a/src/kgc.c b/src/kgc.c
@@ -700,7 +700,6 @@ void klispC_step (klisp_State *K) {
}
}
-
void klispC_fullgc (klisp_State *K) {
if (K->gcstate <= GCSpropagate) {
/* reset sweep marks to sweep all elements (returning them to white) */
diff --git a/src/klispconf.h b/src/klispconf.h
@@ -13,6 +13,10 @@
#include <stdint.h>
#include <stdbool.h>
+/* temp defines till gc is stabilized */
+#define KUSE_GC 1
+/* Print msgs when starting and ending gc */
+#define KDEBUG_GC 1
/*
#define KTRACK_MARKS (true)
@@ -30,7 +34,10 @@
** mean larger pauses which mean slower collection.) You can also change
** this value dynamically.
*/
-#define KLISPI_GCPAUSE 200 /* 200% (wait memory to double before next GC) */
+
+/* In lua that has incremental gc this is setted to 200, in
+ klisp as we don't yet have incremental gc, we set it to 400 */
+#define KLISPI_GCPAUSE 400 /* 400% (wait memory to quadruple before next GC) */
/*
diff --git a/src/kmem.c b/src/kmem.c
@@ -18,6 +18,7 @@
#include "klimits.h"
#include "kmem.h"
#include "kerror.h"
+#include "kgc.h"
/*
** About the realloc function:
@@ -44,7 +45,21 @@
void *klispM_realloc_ (klisp_State *K, void *block, size_t osize, size_t nsize) {
klisp_assert((osize == 0) == (block == NULL));
+ /* TEMP: for now only Stop the world GC */
+ #ifdef KUSE_GC
+ if (K->totalbytes - osize + nsize >= K->GCthreshold) {
+ #ifdef KDEBUG_GC
+ printf("GC START, total_bytes: %d\n", K->totalbytes);
+ #endif
+ klispC_fullgc(K);
+ #ifdef KDEBUG_GC
+ printf("GC END, total_bytes: %d\n", K->totalbytes);
+ #endif
+ }
+ #endif
+
block = (*K->frealloc)(K->ud, block, osize, nsize);
+
if (block == NULL && nsize > 0) {
/* TEMP: try GC if there is no more mem */
/* TODO: make this a catchable error */
diff --git a/src/kstate.c b/src/kstate.c
@@ -177,7 +177,9 @@ klisp_State *klisp_newstate (klisp_Alloc f, void *ud) {
kinit_ground_env(K);
/* set the threshold for gc start now that we have allocated all mem */
- K->GCthreshold = 4*K->totalbytes;
+/* K->GCthreshold = 4*K->totalbytes; */
+ /* TEST */
+ K->GCthreshold = K->totalbytes + 1000;
return K;
}