Refactored the gp_gc code and improved the gc functionality so that gc.scm works as it should

parent b6de7413
#include <pthread.h>
int gp_gc_p = 0;
#ifdef HAS_GP_GC
int gp_gc_counter = 0;
inline void gp_gc_inc(struct gp_stack *gp)
{
unsigned long
ns = gp->gp_nns - gp->gp_si,
nc = gp->gp_nncs - gp->gp_cs,
n = gp->gp_nnc - gp->gp_ci;
n = (nc > n) ? (n > ns ? ns : n) : (nc > ns ? ns : nc);
gp_gc_counter++;
if(n > 10000)
{
gp_gc_counter++;
}
else if (n > 1000)
{
if(gp_gc_counter >= 10000)
{
scm_gc();
gp_gc_counter = 0;
}
}
else if (n > 100)
{
if(gp_gc_counter >= 1000)
{
scm_gc();
gp_gc_counter = 0;
}
}
else
{
if(gp_gc_counter >= 100)
{
scm_gc();
gp_gc_counter = 0;
}
}
}
static int isBefore = 1;
#else
inline void gp_gc_inc(struct gp_stack *gp)
{
}
#endif
pthread_mutex_t gp_gc_lock = PTHREAD_MUTEX_INITIALIZER;
......@@ -49,7 +96,7 @@ void *gp_after_mark_hook(void *hook_data, void *fn_data, void *data)
while(SCM_CONSP(pt))
{
gp_sweep_handle(SCM_CAR(pt));
gp_clear_marks(SCM_CAR(pt), !isBefore);
//gp_clear_marks(SCM_CAR(pt), !isBefore);
pt = SCM_CDR(pt);
}
}
......
......@@ -1080,7 +1080,7 @@ SCM_DEFINE(gp_gc, "gp-gc", 0, 0, 0, (), "clean up the stack")
}
}
}
*/
*/
if(pt1 <= last_save || pt1 <= last_redo)
mute = 1;
......
......@@ -36,6 +36,7 @@ int do_gp_mark = 1;
#define gp_redo_tag 10
#define gp_save_tag 14
SCM_DEFINE(gp_get_current_stack, "gp-current-stack-ref", 0, 0, 0, (),
"takes cdr a prolog pair or scheme pair")
#define FUNC_NAME s_gp_get_current_stack
......@@ -277,7 +278,6 @@ SCM gp_cons_str;
#include "state.c"
static inline SCM gp_make_vector(int n, struct gp_stack *gp)
{
SCM *vec = gp_alloc_data(n + VECTOR_HEADER_SIZE,gp);
......@@ -820,6 +820,8 @@ static inline SCM gp_newframe(SCM s)
gp_debug0("newframe\n");
GP_TEST_CSTACK;
gp_gc_inc(gp);
ci = gp->gp_ci + 4;
l = scm_is_false(l) ? SCM_EOL : l;
......@@ -837,52 +839,21 @@ static inline SCM gp_newframe(SCM s)
}
}
//#define DB(X)
int gp_gc_counter = 0;
static inline SCM* gp_mk_var(SCM s)
{
SCM *ret;
struct gp_stack *gp = get_gp();
int n = gp->gp_nns - gp->gp_si;
gp_debug0("got a gp\n");
if(gp->_logical_) return GP_GETREF(make_logical());
GP_TEST_STACK;
gp_gc_counter++;
if(n > 10000)
{
gp_gc_counter++;
}
else if (n > 1000)
{
if(gp_gc_counter >= 10000)
{
scm_gc();
gp_gc_counter = 0;
}
}
else if (n > 100)
{
if(gp_gc_counter >= 1000)
{
scm_gc();
gp_gc_counter = 0;
}
}
else
{
if(gp_gc_counter >= 100)
{
scm_gc();
gp_gc_counter = 0;
}
}
gp_gc_inc(gp);
ret = get_gp_var(gp);
......@@ -915,6 +886,8 @@ static inline SCM gp_mk_cons(SCM s)
GP_TEST_STACK;
GP_TEST_CSTACK;
gp_gc_inc(gp);
ret = get_gp_cons(gp);
gp_debug0("in cons is %x\n");
......
......@@ -96,12 +96,14 @@ SCM gp_make_cons()
void init_variables()
{
static int x = 0xffff;
SCM y = GP_UNREF(&x);
#ifdef HAS_GP_GC
gp_variable_gc_kind
= GC_new_kind_adv (GC_new_free_list (),
GC_MAKE_PROC (GC_new_proc (gp_mark_variable), 0),
0,1,(GC_word) GPI_SCM_M);
0,1,(GC_word) GPI_SCM_M, SCM_TYP7(y),scm_tc7_smob);
#else
gp_variable_gc_kind
= GC_new_kind(GC_new_free_list (),
......
......@@ -1429,7 +1429,7 @@
(+o m k n))
(<define> (*o n m p)
(<code> (gc))
;(<code> (gc))
(<condi>
((<=> '() n) (<=> '() p))
((poso n) (<=> '() m) (<=> '() p))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment