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.
This commit is contained in:
parent
e4e29f00b0
commit
0bdad95f61
63
mes.c
63
mes.c
|
@ -21,6 +21,7 @@
|
||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -32,11 +33,8 @@
|
||||||
#define QUASISYNTAX 0
|
#define QUASISYNTAX 0
|
||||||
#define ENV_CACHE 1
|
#define ENV_CACHE 1
|
||||||
|
|
||||||
//int ARENA_SIZE = 200000000;
|
int ARENA_SIZE = 100000;
|
||||||
// 30101417
|
int GC_SAFETY = 100;
|
||||||
int ARENA_SIZE = 30000000;
|
|
||||||
int GC_SAFETY = 10000;
|
|
||||||
int GC_FREE = 20000;
|
|
||||||
|
|
||||||
typedef long SCM;
|
typedef long SCM;
|
||||||
enum type_t {CHAR, FUNCTION, MACRO, NUMBER, PAIR, SPECIAL, STRING, SYMBOL, REF, VALUES, VECTOR, BROKEN_HEART};
|
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
|
// Jam Collector
|
||||||
SCM g_symbol_max;
|
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;
|
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
|
SCM
|
||||||
gc ()
|
gc ()
|
||||||
{
|
{
|
||||||
if (g_debug) fprintf (stderr, "***gc[%d]...", g_free.value);
|
if (g_debug) fprintf (stderr, "***gc[%d]...", g_free.value);
|
||||||
g_free.value = 1;
|
g_free.value = 1;
|
||||||
if (!g_news)
|
if (g_cells < g_news) gc_up_arena ();
|
||||||
gc_news ();
|
|
||||||
for (int i=g_free.value; i<g_symbol_max; i++)
|
for (int i=g_free.value; i<g_symbol_max; i++)
|
||||||
gc_copy (i);
|
gc_copy (i);
|
||||||
make_tmps (g_news);
|
make_tmps (g_news);
|
||||||
|
@ -1028,17 +1027,35 @@ add_environment (SCM a, char const *name, SCM x)
|
||||||
}
|
}
|
||||||
|
|
||||||
SCM
|
SCM
|
||||||
mes_symbols () ///((internal))
|
gc_init_cells ()
|
||||||
{
|
{
|
||||||
g_cells = (scm *)malloc (ARENA_SIZE*sizeof(scm));
|
g_cells = (scm *)malloc (2*ARENA_SIZE*sizeof(scm));
|
||||||
g_cells[0].type = VECTOR;
|
g_cells[0].type = VECTOR;
|
||||||
g_cells[0].length = 1000;
|
g_cells[0].length = 1000;
|
||||||
g_cells[0].vector = 0;
|
g_cells[0].vector = 0;
|
||||||
g_cells++;
|
g_cells++;
|
||||||
|
|
||||||
g_cells[0].type = CHAR;
|
g_cells[0].type = CHAR;
|
||||||
g_cells[0].value = 'c';
|
g_cells[0].value = 'c';
|
||||||
g_free.value = 1; // 0 is tricky
|
g_free.value = 1; // 0 is tricky
|
||||||
|
}
|
||||||
|
|
||||||
|
SCM
|
||||||
|
gc_init_news ()
|
||||||
|
{
|
||||||
|
g_news = g_cells-1 + ARENA_SIZE;
|
||||||
|
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';
|
||||||
|
}
|
||||||
|
|
||||||
|
SCM
|
||||||
|
mes_symbols () ///((internal))
|
||||||
|
{
|
||||||
|
gc_init_cells ();
|
||||||
|
gc_init_news ();
|
||||||
|
|
||||||
#include "mes.symbols.i"
|
#include "mes.symbols.i"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue