Fix code heap saving if the last block in the heap is allocated
parent
048db33ac6
commit
48b288ceb9
|
@ -2,9 +2,7 @@
|
||||||
|
|
||||||
- inline float allocation needs a gc check
|
- inline float allocation needs a gc check
|
||||||
- docs: don't pass volatile aliens to callbacks
|
- docs: don't pass volatile aliens to callbacks
|
||||||
- don't save big free chunk at the end of the code heap
|
|
||||||
- some instability remains
|
- some instability remains
|
||||||
- overhaul alien docs
|
|
||||||
|
|
||||||
+ ui:
|
+ ui:
|
||||||
|
|
||||||
|
|
17
vm/code_gc.c
17
vm/code_gc.c
|
@ -118,7 +118,7 @@ CELL heap_allot(F_HEAP *heap, CELL size)
|
||||||
return (CELL)(scan + 1);
|
return (CELL)(scan + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0; /* can't happen */
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* After code GC, all referenced code blocks have status set to B_MARKED, so any
|
/* After code GC, all referenced code blocks have status set to B_MARKED, so any
|
||||||
|
@ -173,13 +173,20 @@ CELL heap_free_space(F_HEAP *heap)
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* The size of the heap, not including the last block if it's free */
|
||||||
CELL heap_size(F_HEAP *heap)
|
CELL heap_size(F_HEAP *heap)
|
||||||
{
|
{
|
||||||
CELL start = heap->base;
|
F_BLOCK *scan = (F_BLOCK *)heap->base;
|
||||||
F_BLOCK *scan = (F_BLOCK *)start;
|
|
||||||
while(next_block(heap,scan))
|
while(next_block(heap,scan) != NULL)
|
||||||
scan = next_block(heap,scan);
|
scan = next_block(heap,scan);
|
||||||
return (CELL)scan - (CELL)start;
|
|
||||||
|
/* this is the last block in the heap, and it is free */
|
||||||
|
if(scan->status == B_FREE)
|
||||||
|
return (CELL)scan - heap->base;
|
||||||
|
/* otherwise the last block is allocated */
|
||||||
|
else
|
||||||
|
return heap->limit - heap->base;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Apply a function to every code block */
|
/* Apply a function to every code block */
|
||||||
|
|
|
@ -103,6 +103,7 @@ bool save_image(const char* filename)
|
||||||
h.bignum_zero = bignum_zero;
|
h.bignum_zero = bignum_zero;
|
||||||
h.bignum_pos_one = bignum_pos_one;
|
h.bignum_pos_one = bignum_pos_one;
|
||||||
h.bignum_neg_one = bignum_neg_one;
|
h.bignum_neg_one = bignum_neg_one;
|
||||||
|
|
||||||
h.code_size = heap_size(&compiling);
|
h.code_size = heap_size(&compiling);
|
||||||
h.code_relocation_base = compiling.base;
|
h.code_relocation_base = compiling.base;
|
||||||
fwrite(&h,sizeof(F_HEADER),1,file);
|
fwrite(&h,sizeof(F_HEADER),1,file);
|
||||||
|
|
Loading…
Reference in New Issue