diff --git a/C/alloc.c b/C/alloc.c index f425c7419..4dd99303a 100644 --- a/C/alloc.c +++ b/C/alloc.c @@ -122,9 +122,7 @@ static char * my_realloc(char *ptr, UInt sz, UInt osz, int safe) long long unsigned int mallocs, reallocs, frees; long long unsigned int tmalloc; -#if DEBUG -#define INSTRUMENT_MALLOC 1 -#endif +#undef INSTRUMENT_MALLOC static inline char * @@ -264,7 +262,6 @@ Yap_InitPreAllocCodeSpace(void) return(NULL); } #if INSTRUMENT_MALLOC - fprintf(stderr,"vsc ptr=%p\n",ptr); sz -= sizeof(CELL); *(CELL*)ptr = sz; ptr += sizeof(CELL); @@ -308,7 +305,6 @@ Yap_ExpandPreAllocCodeSpace(UInt sz0, void *cip, int safe) reallocs++; tmalloc -= ScratchPad.sz; tmalloc += sz; - fprintf(stderr,"vsc ptr=%p\n",ScratchPad.ptr); #endif if (!(ptr = my_realloc(ScratchPad.ptr, sz, ScratchPad.sz, safe))) { Yap_PrologMode &= ~MallocMode; diff --git a/C/amasm.c b/C/amasm.c index 5219856f1..313706b37 100644 --- a/C/amasm.c +++ b/C/amasm.c @@ -3819,6 +3819,7 @@ init_dbterms_list(yamop *code_p, PredEntry *ap) return new; } +#define DEFAULT_NLABELS 4096 yamop * Yap_assemble(int mode, Term t, PredEntry *ap, int is_fact, struct intermediates *cip, UInt max_label) @@ -3835,10 +3836,22 @@ Yap_assemble(int mode, Term t, PredEntry *ap, int is_fact, struct intermediates int clause_has_dbterm = FALSE; #if USE_SYSTEM_MALLOC - cip->label_offset = (Int *)Yap_AllocCodeSpace(sizeof(Int)*max_label); - if (!cip->label_offset) { - save_machine_regs(); - longjmp(cip->CompilerBotch, OUT_OF_HEAP_BOTCH); + if (!Yap_LabelFirstArray && max_label <= DEFAULT_NLABELS) { + Yap_LabelFirstArray = (Int *)Yap_AllocCodeSpace(sizeof(Int)*DEFAULT_NLABELS); + Yap_LabelFirstArraySz = DEFAULT_NLABELS; + if (!Yap_LabelFirstArray) { + save_machine_regs(); + longjmp(cip->CompilerBotch, OUT_OF_HEAP_BOTCH); + } + } + if (Yap_LabelFirstArray && max_label <= Yap_LabelFirstArraySz) { + cip->label_offset = Yap_LabelFirstArray; + } else { + cip->label_offset = (Int *)Yap_AllocCodeSpace(sizeof(Int)*max_label); + if (!cip->label_offset) { + save_machine_regs(); + longjmp(cip->CompilerBotch, OUT_OF_HEAP_BOTCH); + } } #else cip->label_offset = (Int *)cip->freep; @@ -3863,7 +3876,8 @@ Yap_assemble(int mode, Term t, PredEntry *ap, int is_fact, struct intermediates if(!(x = fetch_clause_space(&t,size,cip,&osize))){ #if USE_SYSTEM_MALLOC - Yap_FreeCodeSpace((ADDR)cip->label_offset); + if (cip->label_offset != Yap_LabelFirstArray) + Yap_FreeCodeSpace((ADDR)cip->label_offset); #endif return NULL; } @@ -3880,7 +3894,8 @@ Yap_assemble(int mode, Term t, PredEntry *ap, int is_fact, struct intermediates UInt osize; if(!(x = fetch_clause_space(&t,size,cip,&osize))) { #if USE_SYSTEM_MALLOC - Yap_FreeCodeSpace((ADDR)cip->label_offset); + if (cip->label_offset != Yap_LabelFirstArray) + Yap_FreeCodeSpace((ADDR)cip->label_offset); #endif return NULL; } @@ -3892,7 +3907,8 @@ Yap_assemble(int mode, Term t, PredEntry *ap, int is_fact, struct intermediates cl->ClSize = osize; ProfEnd=code_p; #if USE_SYSTEM_MALLOC - Yap_FreeCodeSpace((ADDR)cip->label_offset); + if (cip->label_offset != Yap_LabelFirstArray) + Yap_FreeCodeSpace((ADDR)cip->label_offset); #endif return entry_code; } else { @@ -3902,7 +3918,8 @@ Yap_assemble(int mode, Term t, PredEntry *ap, int is_fact, struct intermediates Yap_Error_TYPE = OUT_OF_HEAP_ERROR; Yap_Error_Size = size; #if USE_SYSTEM_MALLOC - Yap_FreeCodeSpace((ADDR)cip->label_offset); + if (cip->label_offset != Yap_LabelFirstArray) + Yap_FreeCodeSpace((ADDR)cip->label_offset); #endif return NULL; } @@ -3928,7 +3945,8 @@ Yap_assemble(int mode, Term t, PredEntry *ap, int is_fact, struct intermediates } #endif /* LOW_PROF */ #if USE_SYSTEM_MALLOC - Yap_FreeCodeSpace((ADDR)cip->label_offset); + if (cip->label_offset != Yap_LabelFirstArray) + Yap_FreeCodeSpace((ADDR)cip->label_offset); #endif return entry_code; } diff --git a/C/computils.c b/C/computils.c index 611d528ec..0bba95a3d 100644 --- a/C/computils.c +++ b/C/computils.c @@ -83,31 +83,71 @@ YP_FILE *Yap_logfile; #endif typedef struct mem_blk { - struct mem_blk *next; + union { + struct mem_blk *next; + double fill; + } u; char contents[1]; } MemBlk; +#define CMEM_BLK_SIZE (4*4096) +#define FIRST_CMEM_BLK_SIZE (16*4096) + static char * AllocCMem (int size, struct intermediates *cip) { -#if USE_SYSTEM_MALLOC - struct mem_blk *p = (struct mem_blk *)Yap_AllocCodeSpace(size+sizeof(struct mem_blk *)); - if (!p) { - Yap_Error_Size = size; - save_machine_regs(); - longjmp(cip->CompilerBotch, OUT_OF_HEAP_BOTCH); - } - p->next = cip->blks; - cip->blks = p; - return p->contents; -#else - char *p; - p = cip->freep; #if SIZEOF_INT_P==8 size = (size + 7) & 0xfffffffffffffff8L; #else size = (size + 3) & 0xfffffffcL; #endif +#if USE_SYSTEM_MALLOC + if (!cip->blks || cip->blk_cur+size > cip->blk_top) { + UInt blksz; + struct mem_blk *p; + + if (size > CMEM_BLK_SIZE) + blksz = size+sizeof(struct mem_blk); + else + blksz = CMEM_BLK_SIZE; + if (!cip->blks) { + if (Yap_CMemFirstBlock) { + p = Yap_CMemFirstBlock; + blksz = Yap_CMemFirstBlockSz; + p->u.next = NULL; + } else { + if (blksz < FIRST_CMEM_BLK_SIZE) + blksz = FIRST_CMEM_BLK_SIZE; + p = (struct mem_blk *)Yap_AllocCodeSpace(blksz); + if (!p) { + Yap_Error_Size = size; + save_machine_regs(); + longjmp(cip->CompilerBotch, OUT_OF_HEAP_BOTCH); + } + Yap_CMemFirstBlock = p; + Yap_CMemFirstBlockSz = blksz; + } + } else { + p = (struct mem_blk *)Yap_AllocCodeSpace(blksz); + if (!p) { + Yap_Error_Size = size; + save_machine_regs(); + longjmp(cip->CompilerBotch, OUT_OF_HEAP_BOTCH); + } + } + p->u.next = cip->blks; + cip->blks = p; + cip->blk_cur = p->contents; + cip->blk_top = (char *)p+blksz; + } + { + char *out = cip->blk_cur; + cip->blk_cur += size; + return out; + } +#else + char *p; + p = cip->freep; cip->freep += size; if (ASP <= CellPtr (cip->freep) + 256) { Yap_Error_Size = 256+((char *)cip->freep - (char *)H); @@ -124,8 +164,9 @@ Yap_ReleaseCMem (struct intermediates *cip) #if USE_SYSTEM_MALLOC struct mem_blk *p = cip->blks; while (p) { - struct mem_blk *nextp = p->next; - Yap_FreeCodeSpace((ADDR)p); + struct mem_blk *nextp = p->u.next; + if (p != Yap_CMemFirstBlock) + Yap_FreeCodeSpace((ADDR)p); p = nextp; } cip->blks = NULL; diff --git a/C/heapgc.c b/C/heapgc.c index e05ad8717..a5df09b5e 100644 --- a/C/heapgc.c +++ b/C/heapgc.c @@ -1200,7 +1200,7 @@ mark_variable(CELL_PTR current) next = GET_NEXT(ccur); if (IsVarTerm(ccur)) { - if (IsAttVar(current) && current==next) { + if (IN_BETWEEN(H0,current,H) && IsAttVar(current) && current==next) { mark_att_var(current); POP_CONTINUATION(); } else if (ONHEAP(next)) { diff --git a/C/index.c b/C/index.c index fe532fd66..dde4ca808 100644 --- a/C/index.c +++ b/C/index.c @@ -2666,8 +2666,8 @@ do_blobs(GroupDef *grp, Term t, struct intermediates *cint, UInt argno, int firs ics = fetch_centry(cs, min->Tag, i, n); ics->Tag = min->Tag; - while ((max+1)->Tag == min->Tag && - max != grp->LastClause) max++; + while (max != grp->LastClause && + (max+1)->Tag == min->Tag) max++; if (min != max && (ap->PredFlags & LogUpdatePredFlag)) { ics->u.Label = suspend_indexing(min, max, ap, cint); @@ -3310,7 +3310,6 @@ compile_index(struct intermediates *cint) { PredEntry *ap = cint->CurrentPred; int NClauses = ap->cs.p_code.NOfClauses; - ClauseDef *cls; CELL *top = (CELL *) TR; UInt res; @@ -3319,49 +3318,55 @@ compile_index(struct intermediates *cint) Yap_Error_Size = 0; #if USE_SYSTEM_MALLOC - cls = (ClauseDef *)Yap_AllocCodeSpace(NClauses*sizeof(ClauseDef)); - if (!cls) { - /* tell how much space we need */ - Yap_Error_Size += NClauses*sizeof(ClauseDef); - /* grow stack */ - save_machine_regs(); - longjmp(cint->CompilerBotch,2); + if (!cint->cls) { + cint->cls = (ClauseDef *)Yap_AllocCodeSpace(NClauses*sizeof(ClauseDef)); + if (!cint->cls) { + /* tell how much space we need */ + Yap_Error_Size += NClauses*sizeof(ClauseDef); + /* grow stack */ + save_machine_regs(); + longjmp(cint->CompilerBotch,2); + } } cint->freep = (char *)H; #else /* reserve double the space for compiler */ - cls = (ClauseDef *)H; - if (cls+2*NClauses > (ClauseDef *)(ASP-4096)) { + cint->cls = (ClauseDef *)H; + if (cint->cls+2*NClauses > (ClauseDef *)(ASP-4096)) { /* tell how much space we need */ Yap_Error_Size += NClauses*sizeof(ClauseDef); /* grow stack */ save_machine_regs(); longjmp(cint->CompilerBotch,3); } - cint->freep = (char *)(cls+NClauses); + cint->freep = (char *)(cint->cls+NClauses); #endif if (ap->PredFlags & LogUpdatePredFlag) { /* throw away a label */ new_label(cint); - init_log_upd_clauses(cls,ap); + init_log_upd_clauses(cint->cls,ap); } else if (ap->PredFlags & UDIPredFlag) { UInt lbl = new_label(cint); Yap_emit(user_switch_op, Unsigned(ap), Unsigned(&(ap->cs.p_code.ExpandCode)), cint); -#if USE_SYSTEM_MALLOC - Yap_FreeCodeSpace((ADDR)cls); -#endif return lbl; } else { /* prepare basic data structures */ - init_clauses(cls,ap); + init_clauses(cint->cls,ap); } - res = do_index(cls, cls+(NClauses-1), cint, 1, (UInt)FAILCODE, TRUE, 0, top); -#if USE_SYSTEM_MALLOC - Yap_FreeCodeSpace((ADDR)cls); -#endif + res = do_index(cint->cls, cint->cls+(NClauses-1), cint, 1, (UInt)FAILCODE, TRUE, 0, top); return res; } +static void +CleanCls(struct intermediates *cint) +{ +#if USE_SYSTEM_MALLOC + if (cint->cls) { + Yap_FreeCodeSpace((ADDR)cint->cls); + } +#endif + cint->cls = NULL; +} yamop * Yap_PredIsIndexable(PredEntry *ap, UInt NSlots, yamop *next_pc) @@ -3374,12 +3379,14 @@ Yap_PredIsIndexable(PredEntry *ap, UInt NSlots, yamop *next_pc) cint.CurrentPred = ap; cint.code_addr = NULL; cint.blks = NULL; + cint.cls = NULL; Yap_Error_Size = 0; if ((setjres = setjmp(cint.CompilerBotch)) == 3) { restore_machine_regs(); recover_from_failed_susp_on_cls(&cint, 0); if (!Yap_gcl(Yap_Error_Size, ap->ArityOfPE+NSlots, ENV, next_pc)) { + CleanCls(&cint); Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage); return FAILCODE; } @@ -3387,6 +3394,7 @@ Yap_PredIsIndexable(PredEntry *ap, UInt NSlots, yamop *next_pc) restore_machine_regs(); Yap_Error_Size = recover_from_failed_susp_on_cls(&cint, Yap_Error_Size); if (!Yap_growheap(FALSE, Yap_Error_Size, NULL)) { + CleanCls(&cint); Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage); return FAILCODE; } @@ -3394,6 +3402,7 @@ Yap_PredIsIndexable(PredEntry *ap, UInt NSlots, yamop *next_pc) restore_machine_regs(); recover_from_failed_susp_on_cls(&cint, 0); if (!Yap_growtrail(Yap_Error_Size, FALSE)) { + CleanCls(&cint); Yap_Error(OUT_OF_TRAIL_ERROR, TermNil, Yap_ErrorMessage); return FAILCODE; } @@ -3402,6 +3411,7 @@ Yap_PredIsIndexable(PredEntry *ap, UInt NSlots, yamop *next_pc) recover_from_failed_susp_on_cls(&cint, 0); if (!Yap_growheap(FALSE, Yap_Error_Size, NULL)) { Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage); + CleanCls(&cint); return FAILCODE; } } @@ -3412,6 +3422,7 @@ Yap_PredIsIndexable(PredEntry *ap, UInt NSlots, yamop *next_pc) Yap_ErrorMessage = NULL; if (compile_index(&cint) == (UInt)FAILCODE) { Yap_ReleaseCMem(&cint); + CleanCls(&cint); return FAILCODE; } #ifdef DEBUG @@ -3427,6 +3438,7 @@ Yap_PredIsIndexable(PredEntry *ap, UInt NSlots, yamop *next_pc) if ((indx_out = Yap_assemble(ASSEMBLING_INDEX, TermNil, ap, FALSE, &cint, cint.i_labelno+1)) == NULL) { if (!Yap_growheap(FALSE, Yap_Error_Size, NULL)) { Yap_ReleaseCMem(&cint); + CleanCls(&cint); Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage); return NULL; } @@ -3434,9 +3446,11 @@ Yap_PredIsIndexable(PredEntry *ap, UInt NSlots, yamop *next_pc) } } else { Yap_ReleaseCMem(&cint); + CleanCls(&cint); return NULL; } Yap_ReleaseCMem(&cint); + CleanCls(&cint); if (ap->PredFlags & LogUpdatePredFlag) { LogUpdIndex *cl = ClauseCodeToLogUpdIndex(indx_out); cl->ClFlags |= SwitchRootMask; @@ -3908,7 +3922,7 @@ expand_index(struct intermediates *cint) { PredEntry *ap = cint->CurrentPred; yamop *first, *last = NULL, *alt = NULL; istack_entry *stack, *sp; - ClauseDef *cls = (ClauseDef *)H, *max; + ClauseDef *max; int NClauses; /* last clause to experiment with */ yamop *ipc; @@ -4343,16 +4357,19 @@ expand_index(struct intermediates *cint) { eblk = cint->expand_block = ipc; #if USE_SYSTEM_MALLOC - cls = (ClauseDef *)Yap_AllocCodeSpace(nclauses*sizeof(ClauseDef)); - if (!cls) { - /* tell how much space we need */ - Yap_Error_Size += NClauses*sizeof(ClauseDef); - /* grow stack */ - save_machine_regs(); - longjmp(cint->CompilerBotch,2); + if (!cint->cls) { + cint->cls = (ClauseDef *)Yap_AllocCodeSpace(nclauses*sizeof(ClauseDef)); + if (!cint->cls) { + /* tell how much space we need */ + Yap_Error_Size += NClauses*sizeof(ClauseDef); + /* grow stack */ + save_machine_regs(); + longjmp(cint->CompilerBotch,2); + } } #else - if (cls+2*nclauses > (ClauseDef *)(ASP-4096)) { + cint->cls = (ClauseDef *)H; + if (cint->cls+2*nclauses > (ClauseDef *)(ASP-4096)) { /* tell how much space we need (worst case) */ Yap_Error_Size += 2*NClauses*sizeof(ClauseDef); /* grow stack */ @@ -4361,23 +4378,26 @@ expand_index(struct intermediates *cint) { } #endif if (ap->PredFlags & LogUpdatePredFlag) { - max = install_log_upd_clauseseq(cls, ap, stack, clp, clp+nclauses); + max = install_log_upd_clauseseq(cint->cls, ap, stack, clp, clp+nclauses); } else { - max = install_clauseseq(cls, ap, stack, clp, clp+nclauses); + max = install_clauseseq(cint->cls, ap, stack, clp, clp+nclauses); } } else { cint->expand_block = NULL; #if USE_SYSTEM_MALLOC - cls = (ClauseDef *)Yap_AllocCodeSpace(NClauses*sizeof(ClauseDef)); - if (!cls) { - /* tell how much space we need */ - Yap_Error_Size += NClauses*sizeof(ClauseDef); - /* grow stack */ - save_machine_regs(); - longjmp(cint->CompilerBotch,2); + if (!cint->cls) { + cint->cls = (ClauseDef *)Yap_AllocCodeSpace(NClauses*sizeof(ClauseDef)); + if (!cint->cls) { + /* tell how much space we need */ + Yap_Error_Size += NClauses*sizeof(ClauseDef); + /* grow stack */ + save_machine_regs(); + longjmp(cint->CompilerBotch,2); + } } #else - if (cls+2*NClauses > (ClauseDef *)(ASP-4096)) { + cint->cls = (ClauseDef *)H; + if (cint->cls+2*NClauses > (ClauseDef *)(ASP-4096)) { /* tell how much space we need (worst case) */ Yap_Error_Size += 2*NClauses*sizeof(ClauseDef); save_machine_regs(); @@ -4385,9 +4405,9 @@ expand_index(struct intermediates *cint) { } #endif if (ap->PredFlags & LogUpdatePredFlag) { - max = install_log_upd_clauses(cls, ap, stack, first, last); + max = install_log_upd_clauses(cint->cls, ap, stack, first, last); } else { - max = install_clauses(cls, ap, stack, first, last); + max = install_clauses(cint->cls, ap, stack, first, last); } #if DEBUG_EXPAND if (ap->PredFlags & LogUpdatePredFlag) { @@ -4400,11 +4420,8 @@ expand_index(struct intermediates *cint) { } /* don't count last clause if you don't have to */ if (alt && max->Code == last) max--; - if (max < cls && labp != NULL) { + if (max < cint->cls && labp != NULL) { *labp = FAILCODE; -#if USE_SYSTEM_MALLOC - Yap_FreeCodeSpace((ADDR)cls); -#endif return labp; } #if USE_SYSTEM_MALLOC @@ -4417,14 +4434,14 @@ expand_index(struct intermediates *cint) { if (!IsVarTerm(sp[-1].val) && sp > stack) { if (IsAtomOrIntTerm(sp[-1].val)) { if (s_reg == NULL) { /* we have not yet looked into terms */ - lab = do_index(cls, max, cint, argno+1, fail_l, isfirstcl, clleft, top); + lab = do_index(cint->cls, max, cint, argno+1, fail_l, isfirstcl, clleft, top); } else { UInt arity = 0; if (ap->PredFlags & LogUpdatePredFlag) { - reinstall_log_upd_clauses(cls, max, ap, stack); + reinstall_log_upd_clauses(cint->cls, max, ap, stack); } else { - reinstall_clauses(cls, max, ap, stack); + reinstall_clauses(cint->cls, max, ap, stack); } sp--; while (sp > stack) { @@ -4444,33 +4461,30 @@ expand_index(struct intermediates *cint) { sp--; } } - lab = do_compound_index(cls, max, s_reg, cint, i, arity, argno, fail_l, isfirstcl, is_last_arg, clleft, top, FALSE); + lab = do_compound_index(cint->cls, max, s_reg, cint, i, arity, argno, fail_l, isfirstcl, is_last_arg, clleft, top, FALSE); } } else if (IsPairTerm(sp[-1].val) && sp > stack) { - lab = do_compound_index(cls, max, s_reg, cint, i, 2, argno, fail_l, isfirstcl, is_last_arg, clleft, top, FALSE); + lab = do_compound_index(cint->cls, max, s_reg, cint, i, 2, argno, fail_l, isfirstcl, is_last_arg, clleft, top, FALSE); } else { Functor f = (Functor)RepAppl(sp[-1].val); /* we are continuing within a compound term */ if (IsExtensionFunctor(f)) { - lab = do_index(cls, max, cint, argno+1, fail_l, isfirstcl, clleft, top); + lab = do_index(cint->cls, max, cint, argno+1, fail_l, isfirstcl, clleft, top); } else { - lab = do_compound_index(cls, max, s_reg, cint, i, ArityOfFunctor(f), argno, fail_l, isfirstcl, is_last_arg, clleft, top, FALSE); + lab = do_compound_index(cint->cls, max, s_reg, cint, i, ArityOfFunctor(f), argno, fail_l, isfirstcl, is_last_arg, clleft, top, FALSE); } } } else { if (argno == ap->ArityOfPE) { lab = - do_var_clauses(cls, max, FALSE, cint, isfirstcl, clleft, fail_l, ap->ArityOfPE+1); + do_var_clauses(cint->cls, max, FALSE, cint, isfirstcl, clleft, fail_l, ap->ArityOfPE+1); } else { - lab = do_index(cls, max, cint, argno+1, fail_l, isfirstcl, clleft, top); + lab = do_index(cint->cls, max, cint, argno+1, fail_l, isfirstcl, clleft, top); } } if (labp && !(lab & 1)) { *labp = (yamop *)lab; /* in case we have a single clause */ } -#if USE_SYSTEM_MALLOC - Yap_FreeCodeSpace((ADDR)cls); -#endif return labp; } @@ -4483,6 +4497,7 @@ ExpandIndex(PredEntry *ap, int ExtraArgs, yamop *nextop) { struct intermediates cint; cint.blks = NULL; + cint.cls = NULL; cint.code_addr = NULL; if ((cb = setjmp(cint.CompilerBotch)) == 3) { restore_machine_regs(); @@ -4515,6 +4530,7 @@ ExpandIndex(PredEntry *ap, int ExtraArgs, yamop *nextop) { } #endif Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage); + CleanCls(&cint); return FAILCODE; } } else if (cb == 4) { @@ -4530,6 +4546,7 @@ ExpandIndex(PredEntry *ap, int ExtraArgs, yamop *nextop) { cl = ClauseCodeToStaticIndex(ap->cs.p_code.TrueCodeOfPred); Yap_kill_iblock((ClauseUnion *)cl, NULL, ap); } + CleanCls(&cint); return FAILCODE; } } @@ -4596,6 +4613,7 @@ ExpandIndex(PredEntry *ap, int ExtraArgs, yamop *nextop) { recover_ecls_block(expand_clauses); } Yap_ReleaseCMem(&cint); + CleanCls(&cint); return FAILCODE; } if (*labp == FAILCODE) { @@ -4604,6 +4622,7 @@ ExpandIndex(PredEntry *ap, int ExtraArgs, yamop *nextop) { recover_ecls_block(expand_clauses); } Yap_ReleaseCMem(&cint); + CleanCls(&cint); return FAILCODE; } #ifdef DEBUG @@ -4620,6 +4639,7 @@ ExpandIndex(PredEntry *ap, int ExtraArgs, yamop *nextop) { if (!Yap_growheap(FALSE, Yap_Error_Size, NULL)) { Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage); Yap_ReleaseCMem(&cint); + CleanCls(&cint); return FAILCODE; } goto restart_index; @@ -4631,6 +4651,7 @@ ExpandIndex(PredEntry *ap, int ExtraArgs, yamop *nextop) { recover_ecls_block(expand_clauses); } Yap_ReleaseCMem(&cint); + CleanCls(&cint); return *labp; } if (indx_out == NULL) { @@ -4639,9 +4660,11 @@ ExpandIndex(PredEntry *ap, int ExtraArgs, yamop *nextop) { recover_ecls_block(expand_clauses); } Yap_ReleaseCMem(&cint); + CleanCls(&cint); return FAILCODE; } Yap_ReleaseCMem(&cint); + CleanCls(&cint); *labp = indx_out; if (ap->PredFlags & LogUpdatePredFlag) { /* add to head of current code children */ diff --git a/H/compile.h b/H/compile.h index 0c16089c8..a59d23e20 100644 --- a/H/compile.h +++ b/H/compile.h @@ -252,6 +252,7 @@ typedef struct intermediates { char *freep; char *freep0; struct mem_blk *blks; + char *blk_cur, *blk_top; struct PSEUDO *cpc; struct PSEUDO *CodeStart; struct PSEUDO *icpc; @@ -269,6 +270,8 @@ typedef struct intermediates { /* for expanding code */ yamop **current_try_lab, **current_trust_lab; yamop *try_instructions; + struct StructClauseDef *cls; + /* for expanding code */ union { struct static_index *si; struct logic_upd_index *lui; diff --git a/H/dglobals.h b/H/dglobals.h index 1850fcaf3..92b48e382 100644 --- a/H/dglobals.h +++ b/H/dglobals.h @@ -131,6 +131,12 @@ #define GlobalVariables WL->global_variables #define Yap_AllowRestart WL->allow_restart +#define Yap_CMemFirstBlock WL->cmem_first_block +#define Yap_CMemFirstBlockSz WL->cmem_first_block_sz + +#define Yap_LabelFirstArray WL->label_first_array +#define Yap_LabelFirstArraySz WL->label_first_array_sz + #if (defined(YAPOR) || defined(TABLING)) && defined(THREADS) #define WORKER WL->worker #endif diff --git a/H/hglobals.h b/H/hglobals.h index ba03e9a7a..7107aeeac 100644 --- a/H/hglobals.h +++ b/H/hglobals.h @@ -133,6 +133,12 @@ typedef struct worker_local { struct global_entry* global_variables; int allow_restart; + struct mem_blk* cmem_first_block; + UInt cmem_first_block_sz; + + Int* label_first_array; + UInt label_first_array_sz; + #if (defined(YAPOR) || defined(TABLING)) && defined(THREADS) struct worker worker; #endif diff --git a/H/iglobals.h b/H/iglobals.h index 0078329d6..d05eb3d65 100644 --- a/H/iglobals.h +++ b/H/iglobals.h @@ -131,6 +131,12 @@ static void InitWorker(int wid) { FOREIGN_WL(wid)->global_variables = NULL; FOREIGN_WL(wid)->allow_restart = FALSE; + FOREIGN_WL(wid)->cmem_first_block = NULL; + FOREIGN_WL(wid)->cmem_first_block_sz = 0L; + + FOREIGN_WL(wid)->label_first_array = NULL; + FOREIGN_WL(wid)->label_first_array_sz = 0L; + #if (defined(YAPOR) || defined(TABLING)) && defined(THREADS) #endif diff --git a/H/rglobals.h b/H/rglobals.h index 375a0fb0d..d5db0b367 100644 --- a/H/rglobals.h +++ b/H/rglobals.h @@ -131,6 +131,12 @@ static void RestoreWorker(int wid) { FOREIGN_WL(wid)->global_variables = PtoGlobalEAdjust(FOREIGN_WL(wid)->global_variables); + + + + + + #if (defined(YAPOR) || defined(TABLING)) && defined(THREADS) #endif diff --git a/misc/GLOBALS b/misc/GLOBALS index e4ab5028f..945ae812a 100644 --- a/misc/GLOBALS +++ b/misc/GLOBALS @@ -145,6 +145,14 @@ struct static_array_entry* static_arrays StaticArrays =NULL PtoArraySAdjust struct global_entry* global_variables GlobalVariables =NULL PtoGlobalEAdjust int allow_restart Yap_AllowRestart =FALSE +// Thread Local Area for Fast Storage of Intermediate Compiled Code. +struct mem_blk* cmem_first_block Yap_CMemFirstBlock =NULL +UInt cmem_first_block_sz Yap_CMemFirstBlockSz =0L + +// Thread Local Area for Labels. +Int* label_first_array Yap_LabelFirstArray =NULL +UInt label_first_array_sz Yap_LabelFirstArraySz =0L + // Ricardo's stuff #if (defined(YAPOR) || defined(TABLING)) && defined(THREADS) struct worker worker WORKER void