From f55cfd918a7ba1d380c11ef0eff46c8fc5ac0bb8 Mon Sep 17 00:00:00 2001 From: slava Date: Tue, 26 Sep 2006 21:22:04 +0000 Subject: [PATCH] Image save doesn't write the large free block at the end --- TODO.FACTOR.txt | 3 +-- vm/debug.c | 2 +- vm/heap.c | 9 +++++++++ vm/heap.h | 1 + vm/image.c | 2 +- vm/memory.c | 10 +++++----- vm/memory.h | 4 ++-- 7 files changed, 20 insertions(+), 11 deletions(-) diff --git a/TODO.FACTOR.txt b/TODO.FACTOR.txt index 0f53d72efe..6768f4ec4e 100644 --- a/TODO.FACTOR.txt +++ b/TODO.FACTOR.txt @@ -4,8 +4,7 @@ - test alien-indirect - code GC: - discard the free block at the end of the code heap on save - - minor GC takes too long now - - icache slowdown + - minor GC takes too long now, card mark + ui: diff --git a/vm/debug.c b/vm/debug.c index 880cbbb8a9..6dbeee7857 100644 --- a/vm/debug.c +++ b/vm/debug.c @@ -94,7 +94,7 @@ void dump_cell(CELL cell) fprintf(stderr," -- F"); else if(cell < TYPE_COUNT<>TAG_BITS); - else if(cell >= heap_start && cell < heap_end) + else if(cell >= data_heap_start && cell < data_heap_end) { CELL header = get(UNTAG(cell)); CELL type = header>>TAG_BITS; diff --git a/vm/heap.c b/vm/heap.c index e07ddeead3..d12cc74612 100644 --- a/vm/heap.c +++ b/vm/heap.c @@ -147,3 +147,12 @@ CELL heap_free_space(HEAP *heap) return size; } + +CELL heap_size(HEAP *heap) +{ + CELL start = heap->base; + F_BLOCK *scan = (F_BLOCK *)start; + while(next_block(heap,scan)) + scan = next_block(heap,scan); + return (CELL)scan - (CELL)start; +} diff --git a/vm/heap.h b/vm/heap.h index 06dc330739..cabea8d5fb 100644 --- a/vm/heap.h +++ b/vm/heap.h @@ -23,6 +23,7 @@ void build_free_list(HEAP *heap, CELL size); CELL heap_allot(HEAP *heap, CELL size); void free_unmarked(HEAP *heap); CELL heap_free_space(HEAP *heap); +CELL heap_size(HEAP *heap); INLINE F_BLOCK *next_block(HEAP *heap, F_BLOCK *block) { diff --git a/vm/image.c b/vm/image.c index 3965bad1b1..0518d8bd84 100644 --- a/vm/image.c +++ b/vm/image.c @@ -100,7 +100,7 @@ bool save_image(const char* filename) h.bignum_zero = bignum_zero; h.bignum_pos_one = bignum_pos_one; h.bignum_neg_one = bignum_neg_one; - h.code_size = compiling.limit - compiling.base; + h.code_size = heap_size(&compiling); h.code_relocation_base = compiling.base; fwrite(&h,sizeof(HEADER),1,file); diff --git a/vm/memory.c b/vm/memory.c index f9fa21d905..129546ce68 100644 --- a/vm/memory.c +++ b/vm/memory.c @@ -293,7 +293,7 @@ we need to save its contents and re-initialize it when entering a callback, and restore its contents when leaving the callback. see stack.c */ void update_cards_offset(void) { - cards_offset = (CELL)cards - (heap_start >> CARD_BITS); + cards_offset = (CELL)cards - (data_heap_start >> CARD_BITS); } /* input parameters must be 8 byte aligned */ @@ -316,14 +316,14 @@ void init_arena(CELL gens, CELL young_size, CELL aging_size) gen_count = gens; generations = safe_malloc(sizeof(ZONE) * gen_count); - heap_start = (CELL)(alloc_bounded_block(total_size)->start); - heap_end = heap_start + total_size; + data_heap_start = (CELL)(alloc_bounded_block(total_size)->start); + data_heap_end = data_heap_start + total_size; cards = safe_malloc(cards_size); cards_end = cards + cards_size; update_cards_offset(); - alloter = heap_start; + alloter = data_heap_start; alloter = init_zone(&tenured,aging_size,alloter); alloter = init_zone(&prior,aging_size,alloter); @@ -333,7 +333,7 @@ void init_arena(CELL gens, CELL young_size, CELL aging_size) clear_cards(NURSERY,TENURED); - if(alloter != heap_start + total_size) + if(alloter != data_heap_start + total_size) fatal_error("Oops",alloter); heap_scan = false; diff --git a/vm/memory.h b/vm/memory.h index 18fbf6988f..0554e28373 100644 --- a/vm/memory.h +++ b/vm/memory.h @@ -101,8 +101,8 @@ void primitive_begin_scan(void); void primitive_next_object(void); void primitive_end_scan(void); -CELL heap_start; -CELL heap_end; +CELL data_heap_start; +CELL data_heap_end; /* card marking write barrier. a card is a byte storing a mark flag, and the offset (in cells) of the first object in the card.