From 0bdad95f61fb31b2d3a8f1f97810c30a3f76aa05 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sun, 11 Dec 2016 08:23:15 +0100 Subject: [PATCH] core: Grow gc arena gradually. * mes.c: (gc_up_arena): New function. (gc): Use it when possible. (gc_init_cells, gc_init_news): New function. (mes_symbols): Use them. --- mes.c | 63 +++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 23 deletions(-) diff --git a/mes.c b/mes.c index f9176c37..c239f838 100644 --- a/mes.c +++ b/mes.c @@ -21,6 +21,7 @@ #define _GNU_SOURCE #include #include +#include #include #include #include @@ -32,11 +33,8 @@ #define QUASISYNTAX 0 #define ENV_CACHE 1 -//int ARENA_SIZE = 200000000; -// 30101417 -int ARENA_SIZE = 30000000; -int GC_SAFETY = 10000; -int GC_FREE = 20000; +int ARENA_SIZE = 100000; +int GC_SAFETY = 100; typedef long SCM; enum type_t {CHAR, FUNCTION, MACRO, NUMBER, PAIR, SPECIAL, STRING, SYMBOL, REF, VALUES, VECTOR, BROKEN_HEART}; @@ -894,28 +892,29 @@ make_tmps (scm* cells) // Jam Collector SCM g_symbol_max; -scm * -gc_news () -{ - g_news = (scm *)malloc (ARENA_SIZE*sizeof(scm)); - g_news[0].type = VECTOR; - g_news[0].length = 1000; - g_news[0].vector = 0; - g_news++; - g_news[0].type = CHAR; - g_news[0].value = 'n'; - return g_news; -} - bool g_debug = false; +SCM +gc_up_arena () +{ + ARENA_SIZE *= 2; + void *p = realloc (g_cells-1, 2*ARENA_SIZE*sizeof(scm)); + if (!p) + { + if (g_debug) fprintf (stderr, "cannot up arena: %s: arena=%d\n", strerror (errno), 2*ARENA_SIZE); + return cell_unspecified; + } + g_cells = (scm*)p; + g_cells++; + gc_init_news (); +} + SCM gc () { if (g_debug) fprintf (stderr, "***gc[%d]...", g_free.value); g_free.value = 1; - if (!g_news) - gc_news (); + if (g_cells < g_news) gc_up_arena (); for (int i=g_free.value; i