From 5e3f2dacf4d224205791ba0878699e1e2f751110 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Wed, 27 Nov 2013 13:04:03 +0900 Subject: [PATCH 1/2] Revert "add_heap_page should not be invoked in gc_alloc, but should be in obj_alloc" This reverts commit f11623f07554a470e5f9855459c9aefa3f48b48a. --- src/gc.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/gc.c b/src/gc.c index 1c9fddef..39c61b0b 100644 --- a/src/gc.c +++ b/src/gc.c @@ -139,7 +139,8 @@ gc_alloc(pic_state *pic, size_t size) if (p->s.size >= nunits) break; if (p == freep) { - return NULL; + if ((p = add_heap_page(pic)) == NULL) + return NULL; } } if (p->s.size == nunits) { @@ -493,11 +494,8 @@ pic_obj_alloc_unsafe(pic_state *pic, size_t size, enum pic_tt tt) if (obj == NULL) { pic_gc_run(pic); obj = (struct pic_object *)gc_alloc(pic, size); - if (obj == NULL) { - if (add_heap_page(pic) == NULL) - pic_abort(pic, "GC memory exhausted"); - obj = (struct pic_object *)gc_alloc(pic, size); - } + if (obj == NULL) + pic_abort(pic, "GC memory exhausted"); } obj->tt = tt; From bbe3e990e485e8835fc08c5cdea397d93f0aa966 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Wed, 27 Nov 2013 13:04:12 +0900 Subject: [PATCH 2/2] Revert "pluggable heap pages" This reverts commit e6523730a45bbc0ccc84c21c3edb7cc3ac5e867a. --- include/config.h | 2 +- src/gc.c | 45 +++++++++++++++------------------------------ 2 files changed, 16 insertions(+), 31 deletions(-) diff --git a/include/config.h b/include/config.h index 5b72b9be..28bebc91 100644 --- a/include/config.h +++ b/include/config.h @@ -12,7 +12,7 @@ /* initial memory size (to be dynamically extended if necessary) */ #define PIC_ARENA_SIZE 100 -#define PIC_HEAP_PAGE_SIZE (8192 * 8) +#define PIC_HEAP_SIZE (20000 * 8) #define PIC_STACK_SIZE 1024 #define PIC_RESCUE_SIZE 30 #define PIC_IREP_SIZE 256 diff --git a/src/gc.c b/src/gc.c index 39c61b0b..6f597213 100644 --- a/src/gc.c +++ b/src/gc.c @@ -16,42 +16,28 @@ void init_heap(struct pic_heap *heap) { - heap->base.s.ptr = heap->freep = &heap->base; + int nu; + + nu = (PIC_HEAP_SIZE + sizeof(union header) - 1) / sizeof(union header) + 1; + + heap->base.s.ptr = (union header *)calloc(nu, sizeof(union header)); heap->base.s.size = 0; /* not 1, since it must never be fused into other headers */ heap->base.s.mark = PIC_GC_UNMARK; + heap->freep = heap->base.s.ptr; + heap->freep->s.size = nu - 1; + heap->freep->s.ptr = heap->freep + heap->freep->s.size; + heap->freep->s.mark = PIC_GC_UNMARK; + + heap->freep->s.ptr->s.size = 0; + heap->freep->s.ptr->s.ptr = &heap->base; + heap->freep->s.ptr->s.mark = PIC_GC_UNMARK; + #if GC_DEBUG printf("freep = %p\n", heap->freep); #endif } -static void gc_free(pic_state *, union header *); - -static void * -add_heap_page(pic_state *pic) -{ - int nu; - union header *p, *ep; - -#if DEBUG - puts("heap page added"); -#endif - - nu = (PIC_HEAP_PAGE_SIZE + sizeof(union header) - 1) / sizeof(union header) + 1; - p = (union header *)calloc(nu, sizeof(union header)); - p->s.size = nu - 1; - p->s.mark = PIC_GC_UNMARK; - gc_free(pic, p); - - ep = p + p->s.size; /* end of page */ - ep->s.size = 0; - ep->s.mark = PIC_GC_UNMARK; - ep->s.ptr = p->s.ptr; - p->s.ptr = ep; - - return pic->heap->freep; -} - void * pic_alloc(pic_state *pic, size_t size) { @@ -139,8 +125,7 @@ gc_alloc(pic_state *pic, size_t size) if (p->s.size >= nunits) break; if (p == freep) { - if ((p = add_heap_page(pic)) == NULL) - return NULL; + return 0; } } if (p->s.size == nunits) {