Merge branch 'master' into syntactic-closure
This commit is contained in:
commit
c1788d31b0
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
/* initial memory size (to be dynamically extended if necessary) */
|
/* initial memory size (to be dynamically extended if necessary) */
|
||||||
#define PIC_ARENA_SIZE 100
|
#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_STACK_SIZE 1024
|
||||||
#define PIC_RESCUE_SIZE 30
|
#define PIC_RESCUE_SIZE 30
|
||||||
#define PIC_IREP_SIZE 256
|
#define PIC_IREP_SIZE 256
|
||||||
|
|
51
src/gc.c
51
src/gc.c
|
@ -18,42 +18,28 @@
|
||||||
void
|
void
|
||||||
init_heap(struct pic_heap *heap)
|
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.size = 0; /* not 1, since it must never be fused into other headers */
|
||||||
heap->base.s.mark = PIC_GC_UNMARK;
|
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
|
#if GC_DEBUG
|
||||||
printf("freep = %p\n", heap->freep);
|
printf("freep = %p\n", heap->freep);
|
||||||
#endif
|
#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 *
|
void *
|
||||||
pic_alloc(pic_state *pic, size_t size)
|
pic_alloc(pic_state *pic, size_t size)
|
||||||
{
|
{
|
||||||
|
@ -141,7 +127,7 @@ gc_alloc(pic_state *pic, size_t size)
|
||||||
if (p->s.size >= nunits)
|
if (p->s.size >= nunits)
|
||||||
break;
|
break;
|
||||||
if (p == freep) {
|
if (p == freep) {
|
||||||
return NULL;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (p->s.size == nunits) {
|
if (p->s.size == nunits) {
|
||||||
|
@ -530,11 +516,8 @@ pic_obj_alloc_unsafe(pic_state *pic, size_t size, enum pic_tt tt)
|
||||||
if (obj == NULL) {
|
if (obj == NULL) {
|
||||||
pic_gc_run(pic);
|
pic_gc_run(pic);
|
||||||
obj = (struct pic_object *)gc_alloc(pic, size);
|
obj = (struct pic_object *)gc_alloc(pic, size);
|
||||||
if (obj == NULL) {
|
if (obj == NULL)
|
||||||
if (add_heap_page(pic) == NULL)
|
pic_abort(pic, "GC memory exhausted");
|
||||||
pic_abort(pic, "GC memory exhausted");
|
|
||||||
obj = (struct pic_object *)gc_alloc(pic, size);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
obj->tt = tt;
|
obj->tt = tt;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue