Add crazy paranoia to code GC and flush stderr on Windows
parent
ca588599d1
commit
c968767973
44
vm/code_gc.c
44
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 */
|
/* Add all free blocks to the free list */
|
||||||
while(scan && scan < end)
|
while(scan && scan < end)
|
||||||
{
|
{
|
||||||
if(scan->status == B_FREE)
|
switch(scan->status)
|
||||||
{
|
{
|
||||||
update_free_list(heap,prev_free,scan);
|
update_free_list(heap,prev,scan);
|
||||||
prev_free = scan;
|
prev = scan;
|
||||||
}
|
}
|
||||||
|
|
||||||
prev = scan;
|
prev = scan;
|
||||||
|
@ -161,6 +161,8 @@ void free_unmarked(F_HEAP *heap)
|
||||||
scan->status = B_ALLOCATED;
|
scan->status = B_ALLOCATED;
|
||||||
prev = scan;
|
prev = scan;
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
critical_error("Invalid scan->status",(CELL)scan);
|
||||||
}
|
}
|
||||||
|
|
||||||
scan = next_block(heap,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 */
|
/* 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 reloc_start, CELL literal_start, CELL words_start, CELL words_end)
|
||||||
{
|
{
|
||||||
CELL scan;
|
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)
|
for(scan = literal_start; scan < literal_end; scan += CELLS)
|
||||||
copy_handle((CELL*)scan);
|
copy_handle((CELL*)scan);
|
||||||
|
|
||||||
/* If the block is not finalized, the words area contains pointers to
|
/* If the block is not finalized, the words area contains pointers to
|
||||||
words in the data heap rather than XTs in the code heap */
|
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)
|
for(scan = words_start; scan < words_end; scan += CELLS)
|
||||||
copy_handle((CELL*)scan);
|
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);
|
F_BLOCK *block = xt_to_block(xt);
|
||||||
|
|
||||||
/* If already marked, do nothing */
|
/* If already marked, do nothing */
|
||||||
if(block->status == B_MARKED)
|
switch(block->status)
|
||||||
|
{
|
||||||
|
case B_MARKED:
|
||||||
return;
|
return;
|
||||||
/* Mark it */
|
case B_ALLOCATED:
|
||||||
else if(block->status == B_ALLOCATED)
|
|
||||||
block->status = B_MARKED;
|
block->status = B_MARKED;
|
||||||
/* We should never be asked to mark a free block */
|
break;
|
||||||
else
|
default:
|
||||||
critical_error("Marking the wrong block",(CELL)block);
|
critical_error("Marking the wrong block",(CELL)block);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
F_COMPILED *compiled = xt_to_compiled(xt);
|
F_COMPILED *compiled = xt_to_compiled(xt);
|
||||||
iterate_code_heap_step(compiled,collect_literals_step);
|
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);
|
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 */
|
/* Push the free space and total size of the code heap */
|
||||||
|
|
|
@ -136,6 +136,9 @@ void finalize_code_block(F_COMPILED *relocating, CELL code_start,
|
||||||
{
|
{
|
||||||
CELL scan;
|
CELL scan;
|
||||||
|
|
||||||
|
if(relocating->finalized != false)
|
||||||
|
critical_error("Finalizing a finalized block",relocating);
|
||||||
|
|
||||||
for(scan = words_start; scan < words_end; scan += CELLS)
|
for(scan = words_start; scan < words_end; scan += CELLS)
|
||||||
put(scan,untag_word(get(scan))->xt);
|
put(scan,untag_word(get(scan))->xt);
|
||||||
|
|
||||||
|
|
|
@ -171,7 +171,7 @@ void factorbug(void)
|
||||||
char cmd[1024];
|
char cmd[1024];
|
||||||
|
|
||||||
fprintf(stderr,"READY\n");
|
fprintf(stderr,"READY\n");
|
||||||
fflush(stdout);
|
fflush(stderr);
|
||||||
|
|
||||||
if(scanf("%1000s",cmd) <= 0)
|
if(scanf("%1000s",cmd) <= 0)
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
Loading…
Reference in New Issue