Debugging the code GC

slava 2006-09-28 04:04:34 +00:00
parent 25e8988b86
commit af9fd751a9
1 changed files with 18 additions and 12 deletions

View File

@ -73,6 +73,9 @@ CELL heap_allot(HEAP *heap, CELL size)
{ {
CELL this_size = scan->size - sizeof(F_BLOCK); CELL this_size = scan->size - sizeof(F_BLOCK);
if(scan->status != B_FREE)
critical_error("Invalid block in free list",(CELL)scan);
if(this_size < size) if(this_size < size)
{ {
prev = scan; prev = scan;
@ -109,13 +112,11 @@ CELL heap_allot(HEAP *heap, CELL size)
return (CELL)(scan + 1); return (CELL)(scan + 1);
} }
if(heap->base == 0)
critical_error("Code heap is full",size);
return 0; /* can't happen */ return 0; /* can't happen */
} }
/* free blocks which are allocated and not marked */ /* After code GC, all referenced code blocks have status set to B_MARKED, so any
which are allocated and not marked can be reclaimed. */
void free_unmarked(HEAP *heap) void free_unmarked(HEAP *heap)
{ {
F_BLOCK *prev = NULL; F_BLOCK *prev = NULL;
@ -123,26 +124,31 @@ void free_unmarked(HEAP *heap)
while(scan) while(scan)
{ {
if(scan->status == B_ALLOCATED) switch(scan->status)
{ {
/* merge blocks? */ case B_ALLOCATED:
if(prev && next_block(heap,prev) == scan) if(prev && prev->status == B_FREE)
prev->size += scan->size; prev->size += scan->size;
else else
{ {
scan->status = B_FREE; scan->status = B_FREE;
update_free_list(heap,prev,scan);
prev = scan; prev = scan;
} }
} break;
else if(scan->status == B_MARKED) case B_FREE:
if(prev && prev->status == B_FREE)
prev->size += scan->size;
break;
case B_MARKED:
scan->status = B_ALLOCATED; scan->status = B_ALLOCATED;
prev = scan;
break;
}
scan = next_block(heap,scan); scan = next_block(heap,scan);
} }
if(prev) build_free_list(heap,heap->limit - heap->base);
prev->next_free = NULL;
} }
CELL heap_free_space(HEAP *heap) CELL heap_free_space(HEAP *heap)