From c96876797396a2887f0217594c22f943e77e5212 Mon Sep 17 00:00:00 2001 From: slava Date: Sun, 3 Dec 2006 04:54:19 +0000 Subject: [PATCH] Add crazy paranoia to code GC and flush stderr on Windows --- vm/code_gc.c | 44 ++++++++++++++++++++++++++++++++------------ vm/compiler.c | 3 +++ vm/debug.c | 2 +- 3 files changed, 36 insertions(+), 13 deletions(-) diff --git a/vm/code_gc.c b/vm/code_gc.c index b1205c0dea..b049647fbb 100644 --- a/vm/code_gc.c +++ b/vm/code_gc.c @@ -42,10 +42,10 @@ void build_free_list(F_HEAP *heap, CELL size) /* Add all free blocks to the free list */ while(scan && scan < end) { - if(scan->status == B_FREE) + switch(scan->status) { - update_free_list(heap,prev_free,scan); - prev_free = scan; + update_free_list(heap,prev,scan); + prev = scan; } prev = scan; @@ -161,6 +161,8 @@ void free_unmarked(F_HEAP *heap) scan->status = B_ALLOCATED; prev = scan; break; + default: + critical_error("Invalid scan->status",(CELL)scan); } scan = next_block(heap,scan); @@ -215,22 +217,28 @@ void iterate_code_heap(CODE_HEAP_ITERATOR iter) } /* Copy all literals referenced from a code block to newspace */ -void collect_literals_step(F_COMPILED *relocating, CELL code_start, +void collect_literals_step(F_COMPILED *compiled, CELL code_start, CELL reloc_start, CELL literal_start, CELL words_start, CELL words_end) { CELL scan; - CELL literal_end = literal_start + relocating->literal_length; + CELL literal_end = literal_start + compiled->literal_length; for(scan = literal_start; scan < literal_end; scan += CELLS) copy_handle((CELL*)scan); /* If the block is not finalized, the words area contains pointers to words in the data heap rather than XTs in the code heap */ - if(!relocating->finalized) + switch(compiled->finalized) { + case false: for(scan = words_start; scan < words_end; scan += CELLS) copy_handle((CELL*)scan); + break; + case true: + break; + default: + critical_error("Invalid compiled->finalized",(CELL)compiled); } } @@ -256,20 +264,32 @@ void recursive_mark(CELL xt) F_BLOCK *block = xt_to_block(xt); /* If already marked, do nothing */ - if(block->status == B_MARKED) + switch(block->status) + { + case B_MARKED: return; - /* Mark it */ - else if(block->status == B_ALLOCATED) + case B_ALLOCATED: block->status = B_MARKED; - /* We should never be asked to mark a free block */ - else + break; + default: critical_error("Marking the wrong block",(CELL)block); + break; + } F_COMPILED *compiled = xt_to_compiled(xt); iterate_code_heap_step(compiled,collect_literals_step); - if(compiled->finalized) + switch(compiled->finalized) + { + case false: + break; + case true: iterate_code_heap_step(compiled,mark_sweep_step); + break; + default: + critical_error("Invalid compiled->finalized",(CELL)compiled); + break; + } } /* Push the free space and total size of the code heap */ diff --git a/vm/compiler.c b/vm/compiler.c index cb9a407462..2e58a43c5e 100644 --- a/vm/compiler.c +++ b/vm/compiler.c @@ -136,6 +136,9 @@ void finalize_code_block(F_COMPILED *relocating, CELL code_start, { CELL scan; + if(relocating->finalized != false) + critical_error("Finalizing a finalized block",relocating); + for(scan = words_start; scan < words_end; scan += CELLS) put(scan,untag_word(get(scan))->xt); diff --git a/vm/debug.c b/vm/debug.c index 1ca57c9ee7..76c02d379b 100644 --- a/vm/debug.c +++ b/vm/debug.c @@ -171,7 +171,7 @@ void factorbug(void) char cmd[1024]; fprintf(stderr,"READY\n"); - fflush(stdout); + fflush(stderr); if(scanf("%1000s",cmd) <= 0) exit(1);