fix segfault, clean up code

cvs
Slava Pestov 2005-07-13 19:14:57 +00:00
parent f83823d31d
commit 52c1ea3d25
7 changed files with 17 additions and 14 deletions

View File

@ -61,6 +61,6 @@ void clear_cards(CELL from, CELL to)
void collect_cards(CELL gen)
{
int i;
for(i = gen + 1; i < gc_generations; i++)
for(i = gen + 1; i < gen_count; i++)
collect_gen_cards(i);
}

View File

@ -203,7 +203,7 @@ void dump_generation(ZONE *z)
void dump_generations(void)
{
int i;
for(i = 0; i < gc_generations; i++)
for(i = 0; i < gen_count; i++)
{
fprintf(stderr,"Generation %d: ",i);
dump_generation(&generations[i]);

View File

@ -1,14 +1,14 @@
#include "factor.h"
void init_factor(char* image, CELL ds_size, CELL cs_size,
CELL generations,
CELL gen_count,
CELL young_size, CELL aging_size,
CELL code_size, CELL literal_size)
{
/* initialize random number generator */
srand((unsigned)time(NULL));
init_ffi();
init_arena(generations,young_size,aging_size);
init_arena(gen_count,young_size,aging_size);
init_compiler(code_size);
load_image(image,literal_size);
init_stacks(ds_size,cs_size);
@ -17,7 +17,7 @@ void init_factor(char* image, CELL ds_size, CELL cs_size,
init_errors();
userenv[CPU_ENV] = tag_object(from_c_string(FACTOR_CPU_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);
}

View File

@ -19,17 +19,20 @@ there are two reasons for this:
- 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
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;
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;
gc_generations = gen_count;
gen_count = gens;
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_end = heap_start + total_size;
@ -40,12 +43,12 @@ void init_arena(CELL gen_count, CELL young_size, CELL aging_size)
alloter = heap_start;
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(&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);
clear_cards(NURSERY,TENURED);

View File

@ -11,12 +11,12 @@ typedef struct {
} ZONE;
/* total number of generations. */
CELL gc_generations;
CELL gen_count;
/* the 0th generation is where new objects are allocated. */
#define NURSERY 0
/* the oldest generation */
#define TENURED (gc_generations-1)
#define TENURED (gen_count-1)
ZONE *generations;

View File

@ -146,7 +146,7 @@ void primitive_room(void)
box_signed_cell(compiling.limit - compiling.base);
box_signed_cell(cards_end - cards);
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];
list = cons(cons(

View File

@ -14,7 +14,7 @@
#define ERROR_ENV 12 /* a marker consed onto kernel errors */
#define IN_ENV 13
#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 */
DLLEXPORT CELL userenv[USER_ENV];