fix segfault, clean up code
parent
f83823d31d
commit
52c1ea3d25
|
@ -61,6 +61,6 @@ void clear_cards(CELL from, CELL to)
|
||||||
void collect_cards(CELL gen)
|
void collect_cards(CELL gen)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for(i = gen + 1; i < gc_generations; i++)
|
for(i = gen + 1; i < gen_count; i++)
|
||||||
collect_gen_cards(i);
|
collect_gen_cards(i);
|
||||||
}
|
}
|
||||||
|
|
|
@ -203,7 +203,7 @@ void dump_generation(ZONE *z)
|
||||||
void dump_generations(void)
|
void dump_generations(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for(i = 0; i < gc_generations; i++)
|
for(i = 0; i < gen_count; i++)
|
||||||
{
|
{
|
||||||
fprintf(stderr,"Generation %d: ",i);
|
fprintf(stderr,"Generation %d: ",i);
|
||||||
dump_generation(&generations[i]);
|
dump_generation(&generations[i]);
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
#include "factor.h"
|
#include "factor.h"
|
||||||
|
|
||||||
void init_factor(char* image, CELL ds_size, CELL cs_size,
|
void init_factor(char* image, CELL ds_size, CELL cs_size,
|
||||||
CELL generations,
|
CELL gen_count,
|
||||||
CELL young_size, CELL aging_size,
|
CELL young_size, CELL aging_size,
|
||||||
CELL code_size, CELL literal_size)
|
CELL code_size, CELL literal_size)
|
||||||
{
|
{
|
||||||
/* initialize random number generator */
|
/* initialize random number generator */
|
||||||
srand((unsigned)time(NULL));
|
srand((unsigned)time(NULL));
|
||||||
init_ffi();
|
init_ffi();
|
||||||
init_arena(generations,young_size,aging_size);
|
init_arena(gen_count,young_size,aging_size);
|
||||||
init_compiler(code_size);
|
init_compiler(code_size);
|
||||||
load_image(image,literal_size);
|
load_image(image,literal_size);
|
||||||
init_stacks(ds_size,cs_size);
|
init_stacks(ds_size,cs_size);
|
||||||
|
@ -17,7 +17,7 @@ void init_factor(char* image, CELL ds_size, CELL cs_size,
|
||||||
init_errors();
|
init_errors();
|
||||||
userenv[CPU_ENV] = tag_object(from_c_string(FACTOR_CPU_STRING));
|
userenv[CPU_ENV] = tag_object(from_c_string(FACTOR_CPU_STRING));
|
||||||
userenv[OS_ENV] = tag_object(from_c_string(FACTOR_OS_STRING));
|
userenv[OS_ENV] = tag_object(from_c_string(FACTOR_OS_STRING));
|
||||||
userenv[GEN_ENV] = tag_fixnum(gc_generations);
|
userenv[GEN_ENV] = tag_fixnum(gen_count);
|
||||||
userenv[CARD_OFF_ENV] = tag_cell(cards_offset);
|
userenv[CARD_OFF_ENV] = tag_cell(cards_offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
13
native/gc.c
13
native/gc.c
|
@ -19,17 +19,20 @@ there are two reasons for this:
|
||||||
- the nursery grows into the guard page, so allot() does not have to
|
- the nursery grows into the guard page, so allot() does not have to
|
||||||
check for out of memory, whereas allot_zone() (used by the GC) longjmp()s
|
check for out of memory, whereas allot_zone() (used by the GC) longjmp()s
|
||||||
back to collecting a higher generation */
|
back to collecting a higher generation */
|
||||||
void init_arena(CELL gen_count, CELL young_size, CELL aging_size)
|
void init_arena(CELL gens, CELL young_size, CELL aging_size)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
CELL alloter;
|
CELL alloter;
|
||||||
|
|
||||||
CELL total_size = (gc_generations - 1) * young_size + 2 * aging_size;
|
CELL total_size = (gens - 1) * young_size + 2 * aging_size;
|
||||||
CELL cards_size = total_size / CARD_SIZE;
|
CELL cards_size = total_size / CARD_SIZE;
|
||||||
|
|
||||||
gc_generations = gen_count;
|
gen_count = gens;
|
||||||
generations = malloc(sizeof(ZONE) * gen_count);
|
generations = malloc(sizeof(ZONE) * gen_count);
|
||||||
|
|
||||||
|
if(generations == 0)
|
||||||
|
fatal_error("Cannot allocate zone head array",0);
|
||||||
|
|
||||||
heap_start = (CELL)alloc_guarded(total_size);
|
heap_start = (CELL)alloc_guarded(total_size);
|
||||||
heap_end = heap_start + total_size;
|
heap_end = heap_start + total_size;
|
||||||
|
|
||||||
|
@ -40,12 +43,12 @@ void init_arena(CELL gen_count, CELL young_size, CELL aging_size)
|
||||||
alloter = heap_start;
|
alloter = heap_start;
|
||||||
|
|
||||||
if(heap_start == 0)
|
if(heap_start == 0)
|
||||||
fatal_error("Cannot allocate data heap",total_size);
|
fatal_error("Cannot allocate data heap",0);
|
||||||
|
|
||||||
alloter = init_zone(&tenured,aging_size,alloter);
|
alloter = init_zone(&tenured,aging_size,alloter);
|
||||||
alloter = init_zone(&prior,aging_size,alloter);
|
alloter = init_zone(&prior,aging_size,alloter);
|
||||||
|
|
||||||
for(i = gc_generations - 2; i >= 0; i--)
|
for(i = gen_count - 2; i >= 0; i--)
|
||||||
alloter = init_zone(&generations[i],young_size,alloter);
|
alloter = init_zone(&generations[i],young_size,alloter);
|
||||||
|
|
||||||
clear_cards(NURSERY,TENURED);
|
clear_cards(NURSERY,TENURED);
|
||||||
|
|
|
@ -11,12 +11,12 @@ typedef struct {
|
||||||
} ZONE;
|
} ZONE;
|
||||||
|
|
||||||
/* total number of generations. */
|
/* total number of generations. */
|
||||||
CELL gc_generations;
|
CELL gen_count;
|
||||||
|
|
||||||
/* the 0th generation is where new objects are allocated. */
|
/* the 0th generation is where new objects are allocated. */
|
||||||
#define NURSERY 0
|
#define NURSERY 0
|
||||||
/* the oldest generation */
|
/* the oldest generation */
|
||||||
#define TENURED (gc_generations-1)
|
#define TENURED (gen_count-1)
|
||||||
|
|
||||||
ZONE *generations;
|
ZONE *generations;
|
||||||
|
|
||||||
|
|
|
@ -146,7 +146,7 @@ void primitive_room(void)
|
||||||
box_signed_cell(compiling.limit - compiling.base);
|
box_signed_cell(compiling.limit - compiling.base);
|
||||||
box_signed_cell(cards_end - cards);
|
box_signed_cell(cards_end - cards);
|
||||||
box_signed_cell(prior.limit - prior.base);
|
box_signed_cell(prior.limit - prior.base);
|
||||||
for(gen = gc_generations - 1; gen >= 0; gen--)
|
for(gen = gen_count - 1; gen >= 0; gen--)
|
||||||
{
|
{
|
||||||
ZONE *z = &generations[gen];
|
ZONE *z = &generations[gen];
|
||||||
list = cons(cons(
|
list = cons(cons(
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
#define ERROR_ENV 12 /* a marker consed onto kernel errors */
|
#define ERROR_ENV 12 /* a marker consed onto kernel errors */
|
||||||
#define IN_ENV 13
|
#define IN_ENV 13
|
||||||
#define OUT_ENV 14
|
#define OUT_ENV 14
|
||||||
#define GEN_ENV 15 /* set to gc_generations */
|
#define GEN_ENV 15 /* set to gen_count */
|
||||||
|
|
||||||
/* TAGGED user environment data; see getenv/setenv prims */
|
/* TAGGED user environment data; see getenv/setenv prims */
|
||||||
DLLEXPORT CELL userenv[USER_ENV];
|
DLLEXPORT CELL userenv[USER_ENV];
|
||||||
|
|
Loading…
Reference in New Issue