]> gitweb.factorcode.org Git - factor.git/commitdiff
generation count is now configurable with a command line switch
authorSlava Pestov <slava@factorcode.org>
Wed, 13 Jul 2005 18:53:45 +0000 (18:53 +0000)
committerSlava Pestov <slava@factorcode.org>
Wed, 13 Jul 2005 18:53:45 +0000 (18:53 +0000)
CHANGES.txt
native/cards.c
native/debug.c
native/factor.c
native/gc.c
native/gc.h
native/memory.c
native/run.h

index f5617ae78c0c5d4a46d6b3a562253ed6e4aa781c..17ec48a862354ec659e2cc6c5fcabbbc81dce8cb 100644 (file)
@@ -1,7 +1,11 @@
 Factor 0.76:
 ------------
 
-+ Core language
++ Runtime and core library:
+
+- The number of generations used for garbage collection can now be set
+  with the +G command line switch; eg, +G3 is the default. You must
+  specify at least 2 generations.
 
 - New words:
 
index 4082fc1ca371a9cffac732837a3f1251f607b024..7fbcc30ff806a3b91573ae356d361ddcec954806 100644 (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 < gc_generations; i++)
                collect_gen_cards(i);
 }
index bbe7acc92ce02fd9bb3f7b174347b4987015505a..47839b5a035fd59bb805ccc5eaf499e5a7e2c59e 100644 (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 < gc_generations; i++)
        {
                fprintf(stderr,"Generation %d: ",i);
                dump_generation(&generations[i]);
index 67c784b097a8f8a485bf41a76fa9070837bbd6be..e01edc3dabf751cfa694909d01e7bd235acd21bf 100644 (file)
@@ -1,13 +1,14 @@
 #include "factor.h"
 
 void init_factor(char* image, CELL ds_size, CELL cs_size,
+       CELL generations,
        CELL young_size, CELL aging_size,
        CELL code_size, CELL literal_size)
 {
        /* initialize random number generator */
        srand((unsigned)time(NULL));
        init_ffi();
-       init_arena(young_size,aging_size);
+       init_arena(generations,young_size,aging_size);
        init_compiler(code_size);
        load_image(image,literal_size);
        init_stacks(ds_size,cs_size);
@@ -16,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(gc_generations);
        userenv[CARD_OFF_ENV] = tag_cell(cards_offset);
 }
 
@@ -36,6 +37,7 @@ int main(int argc, char** argv)
 {
        CELL ds_size = 2048;
        CELL cs_size = 2048;
+       CELL generations = 3;
        CELL young_size = 8;
        CELL aging_size = 16;
        CELL code_size = 2;
@@ -49,8 +51,8 @@ int main(int argc, char** argv)
                printf("Runtime options -- n is a number:\n");
                printf(" +Dn   Data stack size, kilobytes\n");
                printf(" +Cn   Call stack size, kilobytes\n");
-               printf(" +Yn   Size of %d youngest generations, megabytes\n",
-                       GC_GENERATIONS-1);
+               printf(" +Gn   Number of generations, must be >= 2\n");
+               printf(" +Yn   Size of n-1 youngest generations, megabytes\n");
                printf(" +An   Size of tenured and semi-spaces, megabytes\n");
                printf(" +Xn   Code heap size, megabytes\n");
                printf(" +Ln   Literal table size, kilobytes. Only for bootstrapping\n");
@@ -64,6 +66,7 @@ int main(int argc, char** argv)
        {
                if(factor_arg(argv[i],"+D%d",&ds_size)) continue;
                if(factor_arg(argv[i],"+C%d",&cs_size)) continue;
+               if(factor_arg(argv[i],"+G%d",&generations)) continue;
                if(factor_arg(argv[i],"+Y%d",&young_size)) continue;
                if(factor_arg(argv[i],"+A%d",&aging_size)) continue;
                if(factor_arg(argv[i],"+X%d",&code_size)) continue;
@@ -79,6 +82,7 @@ int main(int argc, char** argv)
        init_factor(argv[1],
                ds_size * 1024,
                cs_size * 1024,
+               generations,
                young_size * 1024 * 1024,
                aging_size * 1024 * 1024,
                code_size * 1024 * 1024,
index 159eceab50fd80d5714689b561cbafb06d4248a5..91640c497f9e5ccbecce19d09dac503446fa7afe 100644 (file)
@@ -19,14 +19,17 @@ 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 young_size, CELL aging_size)
+void init_arena(CELL gen_count, CELL young_size, CELL aging_size)
 {
        int i;
        CELL alloter;
 
-       CELL total_size = (GC_GENERATIONS - 1) * young_size + 2 * aging_size;
+       CELL total_size = (gc_generations - 1) * young_size + 2 * aging_size;
        CELL cards_size = total_size / CARD_SIZE;
 
+       gc_generations = gen_count;
+       generations = malloc(sizeof(ZONE) * gen_count);
+
        heap_start = (CELL)alloc_guarded(total_size);
        heap_end = heap_start + total_size;
 
@@ -42,7 +45,7 @@ void init_arena(CELL young_size, CELL aging_size)
        alloter = init_zone(&tenured,aging_size,alloter);
        alloter = init_zone(&prior,aging_size,alloter);
 
-       for(i = GC_GENERATIONS - 2; i >= 0; i--)
+       for(i = gc_generations - 2; i >= 0; i--)
                alloter = init_zone(&generations[i],young_size,alloter);
 
        clear_cards(NURSERY,TENURED);
index 023f627c232d95dcc87a8ff303f23e6f3025001a..7814e8d463577e625489ffd2fa02c3362acde6e9 100644 (file)
@@ -11,13 +11,14 @@ typedef struct {
 } ZONE;
 
 /* total number of generations. */
-#define GC_GENERATIONS 3
+CELL gc_generations;
+
 /* the 0th generation is where new objects are allocated. */
 #define NURSERY 0
 /* the oldest generation */
-#define TENURED (GC_GENERATIONS-1)
+#define TENURED (gc_generations-1)
 
-ZONE generations[GC_GENERATIONS];
+ZONE *generations;
 
 /* used during garbage collection only */
 ZONE *newspace;
@@ -35,7 +36,7 @@ INLINE bool in_zone(ZONE* z, CELL pointer)
 
 CELL init_zone(ZONE *z, CELL size, CELL base);
 
-void init_arena(CELL young_size, CELL aging_size);
+void init_arena(CELL gen_count, CELL young_size, CELL aging_size);
 
 /* statistics */
 s64 gc_time;
index 9d9d353e20bce5bc8f57332be899fd37b086f09f..a5d4617e95e17badbe57d8b48f3332c4fc2138df 100644 (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 = gc_generations - 1; gen >= 0; gen--)
        {
                ZONE *z = &generations[gen];
                list = cons(cons(
index 1f4bec23194e0aa39d9156e0dd0dd0a797f44e31..2e61967f08987aacca141dce289f84e6eab748ad 100644 (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 constant */
+#define GEN_ENV        15 /* set to gc_generations */
 
 /* TAGGED user environment data; see getenv/setenv prims */
 DLLEXPORT CELL userenv[USER_ENV];