diff --git a/gc.c b/gc.c index a88d1af0..37752593 100644 --- a/gc.c +++ b/gc.c @@ -17,7 +17,7 @@ gc_heap *gc_heap_create(size_t size, size_t max_size, size_t chunk_size) gc_free_list *free, *next; gc_heap *h; // TODO: mmap? - h = malloc(size); + h = malloc(gc_heap_pad_size(size)); if (!h) return NULL; h->size = size; h->chunk_size = chunk_size; @@ -32,6 +32,14 @@ printf("DEBUG h->data addr: %p\n", h->data); free->next = next; next->size = size - gc_heap_align(gc_free_chunk_size); next->next = NULL; +//#if GC_DEBUG_PRINTFS + fprintf(stderr, ("heap: %p-%p data: %p-%p"), + h, ((char*)h)+sexp_heap_pad_size(size), h->data, h->data + size); + fprintf(stderr, ("first: %p end: %p"), + (object)sexp_heap_first_block(h), (object)sexp_heap_end(h)); + fprintf(stderr, ("free1: %p-%p free2: %p-%p"), + free, ((char*)free)+free->size, next, ((char*)next)+next->size); +//#endif return h; } @@ -101,9 +109,9 @@ void *gc_alloc(gc_heap *h, size_t size, int *heap_grown) exit(1); // TODO: throw error??? } } -#if GC_DEBUG_PRINTFS -// fprintf(stdout, "alloc %p\n", result); -#endif +//#if GC_DEBUG_PRINTFS + fprintf(stdout, "alloc %p size = %d\n", result, size); +//#endif return result; } diff --git a/include/cyclone/types.h b/include/cyclone/types.h index 841ce5a0..d8fc47d1 100644 --- a/include/cyclone/types.h +++ b/include/cyclone/types.h @@ -58,6 +58,7 @@ struct gc_header_type_t { #define gc_heap_first_block(h) ((object)(h->data + gc_heap_align(gc_free_chunk_size))) #define gc_heap_last_block(h) ((object)((char*)h->data + h->size - gc_heap_align(gc_free_chunk_size))) #define gc_heap_end(h) ((object)((char*)h->data + h->size)) +#define gc_heap_pad_size(s) (sizeof(struct gc_heap_t) + (s) + gc_heap_align(1)) #define gc_free_chunk_size (sizeof(gc_free_list)) #define gc_align(n, bits) (((n)+(1<<(bits))-1)&(((unsigned int)-1)-((1<<(bits))-1))) diff --git a/runtime.c b/runtime.c index 41e89435..34429855 100644 --- a/runtime.c +++ b/runtime.c @@ -2716,7 +2716,7 @@ fprintf(stdout, "DEBUG, starting major mark/sweep GC\n"); // JAE DEBUG } max_freed = gc_collect(Cyc_heap, &freed); printf("done, freed = %d, max_freed = %d\n", freed, max_freed); -//exit(1); // JAE DEBUG +exit(1); // JAE DEBUG } //fprintf(stdout, "DEBUG, finished minor GC\n"); // JAE DEBUG