]> gitweb.factorcode.org Git - factor.git/commitdiff
Fix code heap saving if the last block in the heap is allocated
authorslava <slava@factorcode.org>
Sat, 4 Nov 2006 21:51:18 +0000 (21:51 +0000)
committerslava <slava@factorcode.org>
Sat, 4 Nov 2006 21:51:18 +0000 (21:51 +0000)
TODO.FACTOR.txt
vm/code_gc.c
vm/image.c

index 9e592052ae4ccc45549a29f9e15c2f70f070dc4c..fa1d246337088439cbb1a0881bbf47a1f90d7e90 100644 (file)
@@ -2,9 +2,7 @@
 
 - inline float allocation needs a gc check
 - docs: don't pass volatile aliens to callbacks
-- don't save big free chunk at the end of the code heap
 - some instability remains
-- overhaul alien docs
 
 + ui:
 
index 8dae12ffde76fe35eaa7e8016a6d923993f23d10..be3b3b333591cb513fc469b97b6ae242ef546ab7 100644 (file)
@@ -118,7 +118,7 @@ CELL heap_allot(F_HEAP *heap, CELL size)
                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
@@ -173,13 +173,20 @@ CELL heap_free_space(F_HEAP *heap)
        return size;
 }
 
+/* The size of the heap, not including the last block if it's free */
 CELL heap_size(F_HEAP *heap)
 {
-       CELL start = heap->base;
-       F_BLOCK *scan = (F_BLOCK *)start;
-       while(next_block(heap,scan))
+       F_BLOCK *scan = (F_BLOCK *)heap->base;
+
+       while(next_block(heap,scan) != NULL)
                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 */
index 444d71b3d9cf4c2d12580deedb10dae5e4d1cde4..00b0deb100e0072d12b1c6e1af4d0be6abbf57d1 100644 (file)
@@ -103,6 +103,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 = heap_size(&compiling);
        h.code_relocation_base = compiling.base;
        fwrite(&h,sizeof(F_HEADER),1,file);