save all ireps into pic_state

in order to decrease the stress GC will get, restore irep structures
under pic_state instead of under each procs and making it collectable object
This commit is contained in:
Yuichi Nishiwaki 2013-10-16 11:53:25 +09:00
parent c593a46a62
commit f6eddbc6d3
5 changed files with 18 additions and 17 deletions

View File

@ -4,6 +4,7 @@
#define PIC_ARENA_SIZE 100 #define PIC_ARENA_SIZE 100
#define PIC_HEAP_SIZE 8192 #define PIC_HEAP_SIZE 8192
#define PIC_STACK_SIZE 1024 #define PIC_STACK_SIZE 1024
#define PIC_IREP_SIZE 256
#define DEBUG 1 #define DEBUG 1

View File

@ -23,6 +23,9 @@ typedef struct {
pic_value sADD, sSUB, sMUL, sDIV; pic_value sADD, sSUB, sMUL, sDIV;
struct pic_env *global_env; struct pic_env *global_env;
struct pic_irep **irep;
size_t ilen, icapa;
struct heap_page *heap; struct heap_page *heap;
struct pic_object *arena[PIC_ARENA_SIZE]; struct pic_object *arena[PIC_ARENA_SIZE];
int arena_idx; int arena_idx;

View File

@ -30,9 +30,6 @@ struct pic_code {
struct pic_irep { struct pic_irep {
struct pic_code *code; struct pic_code *code;
size_t clen, ccapa; size_t clen, ccapa;
struct pic_irep **proto;
size_t plen, pcapa;
}; };
#endif #endif

View File

@ -37,6 +37,11 @@ pic_open()
pic->heap = (struct heap_page *)malloc(sizeof(struct heap_page)); pic->heap = (struct heap_page *)malloc(sizeof(struct heap_page));
init_heap_page(pic->heap); init_heap_page(pic->heap);
/* irep */
pic->irep = (struct pic_irep **)malloc(sizeof(struct pic_irep *) * PIC_IREP_SIZE);
pic->ilen = 0;
pic->icapa = PIC_IREP_SIZE;
/* GC arena */ /* GC arena */
pic->arena_idx = 0; pic->arena_idx = 0;

View File

@ -165,9 +165,6 @@ new_irep(pic_state *pic)
irep->code = (struct pic_code *)pic_alloc(pic, sizeof(struct pic_code) * 1024); irep->code = (struct pic_code *)pic_alloc(pic, sizeof(struct pic_code) * 1024);
irep->clen = 0; irep->clen = 0;
irep->ccapa = 1024; irep->ccapa = 1024;
irep->proto = NULL;
irep->plen = irep->pcapa = 0;
return irep; return irep;
} }
@ -218,19 +215,11 @@ pic_gen(pic_state *pic, struct pic_irep *irep, pic_value obj, struct pic_env *en
break; break;
} }
else if (pic_eq_p(pic, proc, sLAMBDA)) { else if (pic_eq_p(pic, proc, sLAMBDA)) {
if (irep->proto == NULL) {
irep->proto = (struct pic_irep **)pic_alloc(pic, sizeof(struct pic_irep **) * 5);
irep->pcapa = 5;
}
if (irep->plen >= irep->pcapa) {
irep->proto = (struct pic_irep **)pic_realloc(pic, irep->proto, irep->pcapa * 2);
irep->pcapa *= 2;
}
irep->code[irep->clen].insn = OP_LAMBDA; irep->code[irep->clen].insn = OP_LAMBDA;
irep->code[irep->clen].u.i = irep->plen; irep->code[irep->clen].u.i = pic->ilen;
irep->clen++; irep->clen++;
irep->proto[irep->plen++] = pic_gen_lambda(pic, obj, env); pic->irep[pic->ilen++] = pic_gen_lambda(pic, obj, env);
break; break;
} }
else if (pic_eq_p(pic, proc, sCONS)) { else if (pic_eq_p(pic, proc, sCONS)) {
@ -334,6 +323,12 @@ pic_gen_lambda(pic_state *pic, pic_value obj, struct pic_env *env)
irep->code[irep->clen].insn = OP_RET; irep->code[irep->clen].insn = OP_RET;
irep->clen++; irep->clen++;
#if VM_DEBUG
printf("LAMBDA_%d:\n", pic->ilen);
print_irep(pic, irep);
puts("");
#endif
return irep; return irep;
} }
@ -430,7 +425,7 @@ pic_run(pic_state *pic, struct pic_proc *proc, pic_value args)
proc = (struct pic_proc *)pic_obj_alloc(pic, sizeof(struct pic_proc *), PIC_TT_PROC); proc = (struct pic_proc *)pic_obj_alloc(pic, sizeof(struct pic_proc *), PIC_TT_PROC);
proc->cfunc_p = false; proc->cfunc_p = false;
proc->u.irep = ci->proc->u.irep->proto[pc->u.i]; proc->u.irep = pic->irep[pc->u.i];
PUSH(pic_obj_value(proc)); PUSH(pic_obj_value(proc));
pic_gc_arena_restore(pic, ai); pic_gc_arena_restore(pic, ai);
NEXT; NEXT;