diff --git a/C/agc.c b/C/agc.c index 48abddaf2..98df42468 100644 --- a/C/agc.c +++ b/C/agc.c @@ -326,7 +326,7 @@ clean_atoms(void) #endif *patm = at->NextOfAE; atm = at->NextOfAE; - agc_collected += Yap_SizeOfBlock((CODEADDR)at); + agc_collected += sizeof(AtomEntry)+strlen(at->StrOfAE); Yap_FreeCodeSpace((char *)at); } } @@ -346,7 +346,7 @@ clean_atoms(void) #endif *patm = at->NextOfAE; atm = at->NextOfAE; - agc_collected += Yap_SizeOfBlock((CODEADDR)at); + agc_collected += sizeof(AtomEntry) + strlen(at->StrOfAE); Yap_FreeCodeSpace((char *)at); } } diff --git a/C/alloc.c b/C/alloc.c index f7ff7ad8c..185426198 100644 --- a/C/alloc.c +++ b/C/alloc.c @@ -12,7 +12,7 @@ * Last rev: * * mods: * * comments: allocating space * -* version:$Id: alloc.c,v 1.47 2004-02-20 18:56:06 vsc Exp $ * +* version:$Id: alloc.c,v 1.48 2004-03-05 15:26:32 vsc Exp $ * *************************************************************************/ #ifdef SCCS static char SccsId[] = "%W% %G%"; @@ -56,40 +56,28 @@ static char SccsId[] = "%W% %G%"; #if USE_SYSTEM_MALLOC -int -Yap_SizeOfBlock(CODEADDR p) -{ - return ((UInt *)p)[-1]; -} - char * Yap_AllocCodeSpace(unsigned int size) { - char *ptr = malloc(size+sizeof(UInt)); - UInt *pi = (UInt *)ptr; - pi[0] = size; - return (char *)(pi+1); + return malloc(size); } void Yap_FreeCodeSpace(char *p) { - free (p-sizeof(UInt)); + free (p); } char * Yap_AllocAtomSpace(unsigned int size) { - char *ptr = malloc(size+sizeof(UInt)); - UInt *pi = (UInt *)ptr; - pi[0] = size; - return (char *)(pi+1); + return malloc(size); } void Yap_FreeAtomSpace(char *p) { - free (p-sizeof(UInt)); + free (p); } /* If you need to dinamically allocate space from the heap, this is @@ -259,14 +247,6 @@ STATIC_PROTO(void AddToFreeList, (BlockHeader *)); #define MinHGap 256*K -int -Yap_SizeOfBlock(CODEADDR p) -{ - BlockHeader *b = (BlockHeader *) (p - sizeof(YAP_SEG_SIZE)); - YAP_SEG_SIZE s = (b->b_size) & ~InUseFlag; - return ((s - 1) * sizeof(YAP_SEG_SIZE)); -} - static void RemoveFromFreeList(BlockHeader *b) { diff --git a/C/amasm.c b/C/amasm.c index 2c148e657..9dc901595 100644 --- a/C/amasm.c +++ b/C/amasm.c @@ -99,7 +99,7 @@ STATIC_PROTO(yamop *a_xigl, (op_numbers, yamop *, int, struct PSEUDO *)); STATIC_PROTO(yamop *a_ucons, (int *, compiler_vm_op, yamop *, int, struct intermediates *)); STATIC_PROTO(yamop *a_uvar, (yamop *, int, struct intermediates *)); STATIC_PROTO(yamop *a_wvar, (yamop *, int, struct intermediates *)); -STATIC_PROTO(yamop *do_pass, (int, yamop **, int, int *, struct intermediates *)); +STATIC_PROTO(yamop *do_pass, (int, yamop **, int, int *, struct intermediates *, UInt)); #ifdef DEBUG_OPCODES STATIC_PROTO(void DumpOpCodes, (void)); #endif @@ -2075,7 +2075,7 @@ a_f2(int var, cmp_op_info *cmp_info, yamop *code_p, int pass_no, struct intermed #endif /* YAPOR */ static yamop * -do_pass(int pass_no, yamop **entry_codep, int assembling, int *clause_has_blobsp, struct intermediates *cip) +do_pass(int pass_no, yamop **entry_codep, int assembling, int *clause_has_blobsp, struct intermediates *cip, UInt size) { #ifdef YAPOR #define EITHER_INST 50 @@ -2117,6 +2117,7 @@ do_pass(int pass_no, yamop **entry_codep, int assembling, int *clause_has_blobsp cl_u->luc.ClFlags = LogUpdMask; cl_u->luc.ClRefCount = 0; cl_u->luc.ClPred = cip->CurrentPred; + cl_u->luc.ClSize = size; if (*clause_has_blobsp) { cl_u->luc.ClFlags |= HasBlobsMask; } @@ -2134,6 +2135,7 @@ do_pass(int pass_no, yamop **entry_codep, int assembling, int *clause_has_blobsp if (*clause_has_blobsp) { cl_u->ic.ClFlags |= HasBlobsMask; } + cl_u->ic.ClSize = size; cl_u->ic.ClRefCount = 0; #if defined(YAPOR) || defined(THREADS) INIT_LOCK(cl_u->ic.ClLock); @@ -2147,6 +2149,7 @@ do_pass(int pass_no, yamop **entry_codep, int assembling, int *clause_has_blobsp cl_u->sc.Id = FunctorDBRef; cl_u->sc.ClFlags = StaticMask; cl_u->sc.ClNext = NULL; + cl_u->sc.ClSize = size; if (*clause_has_blobsp) { cl_u->sc.ClFlags |= HasBlobsMask; } @@ -2170,6 +2173,7 @@ do_pass(int pass_no, yamop **entry_codep, int assembling, int *clause_has_blobsp cl_u->lui.ChildIndex = NULL; cl_u->lui.SiblingIndex = NULL; cl_u->lui.u.pred = cip->CurrentPred; + cl_u->lui.ClSize = size; cl_u->lui.ClRefCount = 0; INIT_LOCK(cl_u->lui.ClLock); #if defined(YAPOR) || defined(THREADS) @@ -2190,6 +2194,7 @@ do_pass(int pass_no, yamop **entry_codep, int assembling, int *clause_has_blobsp #endif } else { if (pass_no) { + cl_u->si.ClSize = size; cl_u->si.ClFlags = IndexMask; cl_u->si.ChildIndex = NULL; cl_u->si.SiblingIndex = NULL; @@ -2766,14 +2771,14 @@ Yap_assemble(int mode, Term t, PredEntry *ap, int is_fact, struct intermediates * computes labels offsets and total code size 2 - the second pass * produces the final version of the code */ - CELL size; + UInt size = 0; yamop *entry_code; yamop *code_p; int clause_has_blobs = FALSE; cip->label_offset = (int *)cip->freep; cip->code_addr = NULL; - code_p = do_pass(0, &entry_code, mode, &clause_has_blobs, cip); + code_p = do_pass(0, &entry_code, mode, &clause_has_blobs, cip, size); size = (CELL)NEXTOP(NEXTOP(NEXTOP((yamop *)(((DynamicClause *)NULL)->ClCode),ld),sla),e); if ((CELL)code_p > size) @@ -2845,7 +2850,7 @@ Yap_assemble(int mode, Term t, PredEntry *ap, int is_fact, struct intermediates H = h0; cl = (StaticClause *)((CODEADDR)x-(UInt)size); cip->code_addr = (yamop *)cl; - code_p = do_pass(1, &entry_code, mode, &clause_has_blobs, cip); + code_p = do_pass(1, &entry_code, mode, &clause_has_blobs, cip, size); /* make sure we copy after second pass */ cl->usc.ClSource = x; ProfEnd=code_p; @@ -2858,7 +2863,7 @@ Yap_assemble(int mode, Term t, PredEntry *ap, int is_fact, struct intermediates } } } - code_p = do_pass(1, &entry_code, mode, &clause_has_blobs, cip); + code_p = do_pass(1, &entry_code, mode, &clause_has_blobs, cip, size); ProfEnd=code_p; return entry_code; } diff --git a/C/c_interface.c b/C/c_interface.c index 417596b7b..a8f1cabb8 100644 --- a/C/c_interface.c +++ b/C/c_interface.c @@ -861,7 +861,6 @@ YAP_Init(YAP_init_args *yap_init) { int restore_result; CELL Trail = 0, Stack = 0, Heap = 0; - BACKUP_MACHINE_REGS(); Yap_argv = yap_init->Argv; Yap_argc = yap_init->Argc; @@ -895,6 +894,7 @@ YAP_Init(YAP_init_args *yap_init) yap_init->DelayedReleaseLoad ); Yap_InitExStacks (Trail, Stack); + BACKUP_MACHINE_REGS(); Yap_InitYaamRegs(); #if HAVE_MPI diff --git a/C/cdmgr.c b/C/cdmgr.c index 0b990c938..e1010ab63 100644 --- a/C/cdmgr.c +++ b/C/cdmgr.c @@ -383,7 +383,7 @@ decrease_log_indices(LogUpdIndex *c, yamop *suspend_code) beg->u.Ill.l1 != beg->u.Ill.l2) { end = beg->u.Ill.l2; } else { - end = (yamop *)((CODEADDR)c+Yap_SizeOfBlock((CODEADDR)c)); + end = (yamop *)((CODEADDR)c+c->ClSize); } ipc = beg; cleanup_dangling_indices(ipc, beg, end, suspend_code); @@ -668,8 +668,10 @@ retract_all(PredEntry *p, int in_use) do { if (cl->ClFlags & HasBlobsMask) { DeadClause *dcl = (DeadClause *)cl; + UInt sz = cl->ClSize; dcl->NextCl = DeadClauses; dcl->ClFlags = 0; + dcl->ClSize = sz; DeadClauses = dcl; } else { Yap_FreeCodeSpace((char *)cl); @@ -1289,8 +1291,10 @@ Yap_EraseStaticClause(StaticClause *cl, Term mod) { WRITE_UNLOCK(ap->PRWLock); if (cl->ClFlags & HasBlobsMask || static_in_use(ap,TRUE)) { DeadClause *dcl = (DeadClause *)cl; + UInt sz = cl->ClSize; dcl->NextCl = DeadClauses; dcl->ClFlags = 0; + dcl->ClSize = sz; DeadClauses = dcl; } else { Yap_FreeCodeSpace((char *)cl); @@ -1631,8 +1635,10 @@ purge_clauses(PredEntry *pred) do { if (cl->ClFlags & HasBlobsMask || in_use) { DeadClause *dcl = (DeadClause *)cl; + UInt sz = cl->ClSize; dcl->NextCl = DeadClauses; dcl->ClFlags = 0; + dcl->ClSize = sz; DeadClauses = dcl; } else { Yap_FreeCodeSpace((char *)cl); @@ -2226,7 +2232,7 @@ static yamop *cur_clause(PredEntry *pe, yamop *codeptr) cl = ClauseCodeToStaticClause(pe->cs.p_code.FirstClause); do { - if (IN_BLOCK(codeptr,cl,Yap_SizeOfBlock((CODEADDR)cl))) { + if (IN_BLOCK(codeptr,cl,cl->ClSize)) { return cl->ClCode; } if (cl->ClCode == pe->cs.p_code.LastClause) @@ -2242,7 +2248,7 @@ static yamop *cur_log_upd_clause(PredEntry *pe, yamop *codeptr) LogUpdClause *cl; cl = ClauseCodeToLogUpdClause(pe->cs.p_code.FirstClause); do { - if (IN_BLOCK(codeptr,cl->ClCode,Yap_SizeOfBlock((CODEADDR)cl))) { + if (IN_BLOCK(codeptr,cl->ClCode,cl->ClSize)) { return((yamop *)cl->ClCode); } cl = cl->ClNext; @@ -2255,7 +2261,7 @@ static LogUpdIndex * find_owner_log_index(LogUpdIndex *cl, yamop *code_p) { yamop *code_beg = cl->ClCode; - yamop *code_end = (yamop *)((char *)cl + Yap_SizeOfBlock((CODEADDR)cl)); + yamop *code_end = (yamop *)((char *)cl + cl->ClSize); if (code_p >= code_beg && code_p <= code_end) { return cl; @@ -2275,7 +2281,7 @@ static StaticIndex * find_owner_static_index(StaticIndex *cl, yamop *code_p) { yamop *code_beg = cl->ClCode; - yamop *code_end = (yamop *)((char *)cl + Yap_SizeOfBlock((CODEADDR)cl)); + yamop *code_end = (yamop *)((char *)cl + cl->ClSize); if (code_p >= code_beg && code_p <= code_end) { return cl; @@ -2595,7 +2601,7 @@ code_in_pred_info(PredEntry *pp, Atom *pat, UInt *parity) { static int code_in_pred_lu_index(LogUpdIndex *icl, yamop *codeptr) { LogUpdIndex *cicl; - if (IN_BLOCK(codeptr,icl,Yap_SizeOfBlock((CODEADDR)icl))) { + if (IN_BLOCK(codeptr,icl,icl->ClSize)) { return TRUE; } cicl = icl->ChildIndex; @@ -2610,7 +2616,7 @@ code_in_pred_lu_index(LogUpdIndex *icl, yamop *codeptr) { static int code_in_pred_s_index(StaticIndex *icl, yamop *codeptr) { StaticIndex *cicl; - if (IN_BLOCK(codeptr,icl,Yap_SizeOfBlock((CODEADDR)icl))) { + if (IN_BLOCK(codeptr,icl,icl->ClSize)) { return TRUE; } cicl = icl->ChildIndex; @@ -2649,17 +2655,17 @@ code_in_pred(PredEntry *pp, Atom *pat, UInt *parity, yamop *codeptr) { char *code_end; if (pp->PredFlags & LogUpdatePredFlag) { LogUpdClause *cl = ClauseCodeToLogUpdClause(pp->cs.p_code.TrueCodeOfPred); - code_end = (char *)cl + Yap_SizeOfBlock((CODEADDR)cl); + code_end = (char *)cl + cl->ClSize; } else if (!(pp->PredFlags & DynamicPredFlag)) { code_end = NULL; } else { StaticClause *cl = ClauseCodeToStaticClause(pp->cs.p_code.TrueCodeOfPred); - code_end = (char *)cl + Yap_SizeOfBlock((CODEADDR)cl); + code_end = (char *)cl + cl->ClSize; } if (pp->PredFlags & LogUpdatePredFlag) { LogUpdClause *cl = ClauseCodeToLogUpdClause(clcode); do { - if (IN_BLOCK(codeptr,(CODEADDR)cl,Yap_SizeOfBlock((CODEADDR)cl))) { + if (IN_BLOCK(codeptr,(CODEADDR)cl,cl->ClSize)) { clause_was_found(pp, pat, parity); READ_UNLOCK(pp->PRWLock); return i; @@ -2669,10 +2675,10 @@ code_in_pred(PredEntry *pp, Atom *pat, UInt *parity, yamop *codeptr) { } while (cl != NULL); } else if (pp->PredFlags & DynamicPredFlag) { do { - CODEADDR cl; + DynamicClause *cl; - cl = (CODEADDR)ClauseCodeToDynamicClause(clcode); - if (IN_BLOCK(codeptr,cl,Yap_SizeOfBlock((CODEADDR)cl))) { + cl = ClauseCodeToDynamicClause(clcode); + if (IN_BLOCK(codeptr,cl,cl->ClSize)) { clause_was_found(pp, pat, parity); READ_UNLOCK(pp->PRWLock); return i; @@ -2687,7 +2693,7 @@ code_in_pred(PredEntry *pp, Atom *pat, UInt *parity, yamop *codeptr) { cl = ClauseCodeToStaticClause(clcode); do { - if (IN_BLOCK(codeptr,cl,Yap_SizeOfBlock((CODEADDR)cl))) { + if (IN_BLOCK(codeptr,cl,cl->ClSize)) { clause_was_found(pp, pat, parity); READ_UNLOCK(pp->PRWLock); return i; @@ -3471,7 +3477,7 @@ add_code_in_pred(PredEntry *pp) { clcode = pp->CodeOfPred; cl = ClauseCodeToStaticClause(clcode); - code_end = (char *)cl + Yap_SizeOfBlock((CODEADDR)cl); + code_end = (char *)cl + cl->ClSize; Yap_inform_profiler_of_clause(clcode, (yamop *)code_end, pp,0); READ_UNLOCK(pp->PRWLock); return; @@ -3481,10 +3487,10 @@ add_code_in_pred(PredEntry *pp) { char *code_end; if (pp->PredFlags & LogUpdatePredFlag) { LogUpdIndex *cl = ClauseCodeToLogUpdIndex(clcode); - code_end = (char *)cl + Yap_SizeOfBlock((CODEADDR)cl); + code_end = (char *)cl + cl->ClSize; } else { StaticIndex *cl = ClauseCodeToStaticIndex(clcode); - code_end = (char *)cl + Yap_SizeOfBlock((CODEADDR)cl); + code_end = (char *)cl + cl->ClSize; } Yap_inform_profiler_of_clause(clcode, (yamop *)code_end, pp,0); } @@ -3495,17 +3501,17 @@ add_code_in_pred(PredEntry *pp) { do { char *code_end; - code_end = (char *)cl + Yap_SizeOfBlock((CODEADDR)cl); + code_end = (char *)cl + cl->ClSize; Yap_inform_profiler_of_clause(cl->ClCode, (yamop *)code_end, pp,0); cl = cl->ClNext; } while (cl != NULL); } else if (pp->PredFlags & DynamicPredFlag) { do { - CODEADDR cl; + DynamicClause *cl; char *code_end; - cl = (CODEADDR)ClauseCodeToDynamicClause(clcode); - code_end = cl + Yap_SizeOfBlock((CODEADDR)cl); + cl = ClauseCodeToDynamicClause(clcode); + code_end = (CODEADDR)cl + cl->ClSize; Yap_inform_profiler_of_clause(clcode, (yamop *)code_end, pp,0); if (clcode == pp->cs.p_code.LastClause) break; @@ -3516,7 +3522,7 @@ add_code_in_pred(PredEntry *pp) { do { char *code_end; - code_end = (char *)cl + Yap_SizeOfBlock((CODEADDR)cl); + code_end = (char *)cl + cl->ClSize; Yap_inform_profiler_of_clause(cl->ClCode, (yamop *)code_end, pp,0); if (cl->ClCode == pp->cs.p_code.FirstClause) break; @@ -3558,7 +3564,7 @@ Yap_dump_code_area_for_profiler(void) { static UInt index_ssz(StaticIndex *x) { - UInt sz = Yap_SizeOfBlock((CODEADDR)x); + UInt sz = x->ClSize; x = x->ChildIndex; while (x != NULL) { sz += index_ssz(x); @@ -3576,7 +3582,7 @@ static_statistics(PredEntry *pe) if (pe->cs.p_code.NOfClauses) { do { cls++; - sz += Yap_SizeOfBlock((CODEADDR)cl); + sz += cl->ClSize; if (cl->ClCode == pe->cs.p_code.LastClause) break; cl = cl->ClNext; diff --git a/C/dbase.c b/C/dbase.c index 530dfe889..d71ac3b2b 100644 --- a/C/dbase.c +++ b/C/dbase.c @@ -3489,7 +3489,7 @@ p_first_instance(void) static UInt index_sz(LogUpdIndex *x) { - UInt sz = Yap_SizeOfBlock((CODEADDR)x); + UInt sz = x->ClSize; x = x->ChildIndex; while (x != NULL) { sz += index_sz(x); @@ -3513,7 +3513,7 @@ lu_statistics(PredEntry *pe) x = ClauseCodeToLogUpdClause(pe->cs.p_code.FirstClause); while (x != NULL) { cls++; - sz += Yap_SizeOfBlock((CODEADDR)x); + sz += x->ClSize; x = x->ClNext; } } @@ -3549,10 +3549,10 @@ p_key_statistics(void) x = p->First; while (x != NULL) { cls++; - sz += Yap_SizeOfBlock((CODEADDR)x); + sz += sizeof(DBStruct)+sizeof(CELL)*x->DBT.NOfCells; if (x->Code) { DynamicClause *cl = ClauseCodeToDynamicClause(x->Code); - sz += Yap_SizeOfBlock((CODEADDR)cl); + sz += cl->ClSize; } x = NextDBRef(x); } @@ -3574,12 +3574,12 @@ p_total_erased(void) /* only for log upds */ while (cl) { cls++; - sz += Yap_SizeOfBlock((CODEADDR)cl); + sz += cl->ClSize; cl = cl->ClNext; } while (icl) { icls++; - isz += Yap_SizeOfBlock((CODEADDR)icl); + isz += icl->ClSize; icl = icl->SiblingIndex; } return @@ -3605,7 +3605,7 @@ p_key_erased_statistics(void) while (cl) { if (cl->ClPred == pe) { cls++; - sz += Yap_SizeOfBlock((CODEADDR)cl); + sz += cl->ClSize; } cl = cl->ClNext; } @@ -3616,7 +3616,7 @@ p_key_erased_statistics(void) c = c->u.ParentIndex; if (pe == c->u.pred) { icls++; - isz += Yap_SizeOfBlock((CODEADDR)icl); + isz += c->ClSize; } icl = icl->SiblingIndex; } diff --git a/C/heapgc.c b/C/heapgc.c index aa3add4ee..0ee44a04f 100644 --- a/C/heapgc.c +++ b/C/heapgc.c @@ -503,7 +503,7 @@ static dbentry db_vec, db_vec0; /* init the table */ static void -store_in_dbtable(CODEADDR entry, db_entry_type db_type) +store_in_dbtable(CODEADDR entry, CODEADDR end, db_entry_type db_type) { dbentry parent = db_vec0; dbentry new = db_vec; @@ -512,7 +512,7 @@ store_in_dbtable(CODEADDR entry, db_entry_type db_type) Yap_growtrail(64 * 1024L); new->val = entry; new->db_type = db_type; - new->lim = entry+Yap_SizeOfBlock((CODEADDR)entry); + new->lim = entry+sizeof(DBStruct)+sizeof(CELL)*((DBRef)entry)->DBT.NOfCells; new->left = new->right = NULL; if (db_vec == db_vec0) { db_vec++; @@ -616,20 +616,26 @@ init_dbtable(tr_fr_ptr trail_ptr) { /* for the moment, if all references to the term in the stacks are only pointers, reset the flag */ if (FlagOn(DBClMask, flags)) { - store_in_dbtable((CODEADDR)DBStructFlagsToDBStruct(pt0), db_entry); + DBRef dbr = DBStructFlagsToDBStruct(pt0); + store_in_dbtable((CODEADDR)dbr, + (CODEADDR)dbr+sizeof(DBStruct)+sizeof(CELL)*dbr->DBT.NOfCells, + db_entry); } else if (flags & LogUpdMask) { if (flags & IndexMask) { - store_in_dbtable((CODEADDR)ClauseFlagsToLogUpdIndex(pt0), li_entry); + LogUpdIndex *li = ClauseFlagsToLogUpdIndex(pt0); + store_in_dbtable((CODEADDR)li, (CODEADDR)li+li->ClSize, li_entry); } else { - store_in_dbtable((CODEADDR)ClauseFlagsToLogUpdClause(pt0), lcl_entry); + LogUpdClause *cli = ClauseFlagsToLogUpdClause(pt0); + store_in_dbtable((CODEADDR)cli, (CODEADDR)cli+cli->ClSize, lcl_entry); } } else { - store_in_dbtable((CODEADDR)ClauseFlagsToDynamicClause(pt0), cl_entry); + DynamicClause *dcl = ClauseFlagsToDynamicClause(pt0); + store_in_dbtable((CODEADDR)dcl, (CODEADDR)dcl->ClSize, dcl_entry); } } } while (cl != NULL) { - store_in_dbtable((CODEADDR)cl, dcl_entry); + store_in_dbtable((CODEADDR)cl, (CODEADDR)cl+cl->ClSize, dcl_entry); cl = cl->NextCl; } if (db_vec == db_vec0) { diff --git a/C/index.c b/C/index.c index f933bc5e5..d3ace8f68 100644 --- a/C/index.c +++ b/C/index.c @@ -2406,23 +2406,27 @@ emit_switch_space(UInt n, UInt item_size, struct intermediates *cint) PredEntry *ap = cint->CurrentPred; if (ap->PredFlags & LogUpdatePredFlag) { - LogUpdIndex *cl = (LogUpdIndex *)Yap_AllocCodeSpace(sizeof(LogUpdIndex)+n*item_size); + UInt sz = sizeof(LogUpdIndex)+n*item_size; + LogUpdIndex *cl = (LogUpdIndex *)Yap_AllocCodeSpace(sz); if (cl == NULL) { Yap_Error_Size = sizeof(LogUpdIndex)+n*item_size; /* grow stack */ longjmp(cint->CompilerBotch,2); } cl->ClFlags = SwitchTableMask|LogUpdMask; + cl->ClSize = sz; /* insert into code chain */ return cl->ClCode; } else { - StaticIndex *cl = (StaticIndex *)Yap_AllocCodeSpace(sizeof(StaticIndex)+n*item_size); + UInt sz = sizeof(StaticIndex)+n*item_size; + StaticIndex *cl = (StaticIndex *)Yap_AllocCodeSpace(sz); if (cl == NULL) { Yap_Error_Size = sizeof(LogUpdIndex)+n*item_size; /* grow stack */ longjmp(cint->CompilerBotch,2); } cl->ClFlags = SwitchTableMask; + cl->ClSize = sz; return cl->ClCode; /* insert into code chain */ } @@ -4323,10 +4327,15 @@ cross_block(path_stack_entry *sp, yamop **pipc, PredEntry *ap) ClauseUnion *block; do { + UInt bsize; while ((--tsp)->flag != block_entry); block = tsp->u.cle.block; + if (block->lui.ClFlags & LogUpdMask) + bsize = block->lui.ClSize; + else + bsize = block->si.ClSize; if (ipc > (yamop *)block && - ipc <= (yamop *)((CODEADDR)block + Yap_SizeOfBlock((CODEADDR)block))) { + ipc <= (yamop *)((CODEADDR)block + bsize)) { path_stack_entry *nsp = tsp+1; for (;tspflag == pc_entry) { @@ -4926,6 +4935,8 @@ insertz_in_lu_block(LogUpdIndex *blk, PredEntry *ap, yamop *code) { op_numbers op = Yap_op_from_opcode(blk->ClCode->opc); yamop *end, *last, *where, *next; + UInt bsize; + /* make sure this is something I can work with */ if (op != _enter_lu_pred && op != _stale_lu_index) { if (blk->ClFlags & SwitchRootMask) { @@ -4937,7 +4948,8 @@ insertz_in_lu_block(LogUpdIndex *blk, PredEntry *ap, yamop *code) } /* ok, we are in a sequence of try-retry-trust instructions, or something similar */ - end = (yamop *)((CODEADDR)blk+Yap_SizeOfBlock((CODEADDR)blk)); + bsize = blk->ClSize; + end = (yamop *)((CODEADDR)blk+bsize); where = last = blk->ClCode->u.Ill.l2; next = NEXTOP(NEXTOP(where, ld),p); /* trust logical followed by trust */ last = PREVOP(last, ld); @@ -6158,11 +6170,11 @@ Yap_RemoveClauseFromIndex(PredEntry *ap, yamop *beg) { if (ap->PredFlags & LogUpdatePredFlag) { LogUpdClause *c = ClauseCodeToLogUpdClause(beg); cl.Code = cl.CurrentCode = beg; - last = (yamop *)((CODEADDR)c+Yap_SizeOfBlock((CODEADDR)c)); + last = (yamop *)((CODEADDR)c+c->ClSize); } else { StaticClause *c = ClauseCodeToStaticClause(beg); cl.Code = cl.CurrentCode = beg; - last = (yamop *)((CODEADDR)c+Yap_SizeOfBlock((CODEADDR)c)); + last = (yamop *)((CODEADDR)c+c->ClSize); } sp = push_path(stack, NULL, &cl); if (ap->cs.p_code.NOfClauses == 0) { diff --git a/C/threads.c b/C/threads.c index ed0afae60..0596c076c 100644 --- a/C/threads.c +++ b/C/threads.c @@ -214,7 +214,6 @@ static Int p_thread_exit(void) { thread_die(worker_id, FALSE); - fprintf(stderr,"here i go %d %ld\n", worker_id, ThreadHandle[worker_id].handle); pthread_exit(NULL); return TRUE; } diff --git a/C/unify.c b/C/unify.c index cbc417622..6be88cbcd 100644 --- a/C/unify.c +++ b/C/unify.c @@ -295,6 +295,9 @@ cufail: #if SHADOW_REGS #if defined(B) || defined(TR) #undef Yap_REGS +#if PUSH_REGS +#define Yap_REGS (*Yap_regp) +#endif #endif /* defined(B) || defined(TR) */ #endif } diff --git a/H/Regs.h b/H/Regs.h index 6259d3a13..d840708fd 100644 --- a/H/Regs.h +++ b/H/Regs.h @@ -10,7 +10,7 @@ * File: Regs.h * * mods: * * comments: YAP abstract machine registers * -* version: $Id: Regs.h,v 1.26 2004-02-12 12:37:11 vsc Exp $ * +* version: $Id: Regs.h,v 1.27 2004-03-05 15:26:33 vsc Exp $ * *************************************************************************/ @@ -185,7 +185,7 @@ extern int Yap_stack_overflows; #define H0 Yap_REGS.H0_ /* base of heap (global) stack */ #define LCL0 Yap_REGS.LCL0_ /* local stack base */ -#if defined(__GNUC__) && defined(sparc) && !defined(__NetBSD__) +#if defined(__GNUC__) && defined(sparc) && !defined(__NetBSD__) && !defined(THREADS) #define P Yap_REGS.P_ /* prolog machine program counter */ #define YENV Yap_REGS.YENV_ /* current environment (may differ from ENV)*/ @@ -193,7 +193,7 @@ extern int Yap_stack_overflows; register CELL *H asm ("g6"); register tr_fr_ptr TR asm ("g7"); -#ifdef __svr4__ +#if defined(__svr4__) register choiceptr B asm ("g5"); #else #define B Yap_REGS.B_ /* latest choice point */ @@ -205,7 +205,7 @@ register choiceptr B asm ("g5"); EXTERN inline void save_machine_regs(void) { Yap_REGS.H_ = H; Yap_REGS.TR_ = TR; -#ifdef __svr4__ +#if defined(__svr4__) Yap_REGS.B_ = B; #endif } @@ -213,7 +213,7 @@ EXTERN inline void save_machine_regs(void) { EXTERN inline void restore_machine_regs(void) { H = Yap_REGS.H_; TR = Yap_REGS.TR_; -#ifdef __svr4__ +#if defined(__svr4__) B = Yap_REGS.B_; #endif } @@ -243,18 +243,18 @@ EXTERN inline void restore_H(void) { #define RECOVER_H() save_H(); H = BK_H EXTERN inline void save_B(void) { -#ifdef __svr4__ +#if defined(__svr4__) Yap_REGS.B_ = B; #endif } EXTERN inline void restore_B(void) { -#ifdef __svr4__ +#if defined(__svr4__) B = Yap_REGS.B_; #endif } -#ifdef __svr4__ +#if defined(__svr4__) #define BACKUP_B() choiceptr BK_B = B; restore_B() #define RECOVER_B() save_B(); B = BK_B diff --git a/H/Yapproto.h b/H/Yapproto.h index b07f919c0..bb79ab2ad 100644 --- a/H/Yapproto.h +++ b/H/Yapproto.h @@ -10,7 +10,7 @@ * File: Yap.proto * * mods: * * comments: Function declarations for YAP * -* version: $Id: Yapproto.h,v 1.50 2004-03-04 18:33:33 vsc Exp $ * +* version: $Id: Yapproto.h,v 1.51 2004-03-05 15:26:33 vsc Exp $ * *************************************************************************/ /* prototype file for Yap */ @@ -68,7 +68,6 @@ void STD_PROTO(Yap_atom_gc, (void)); void STD_PROTO(Yap_init_agc, (void)); /* alloc.c */ -int STD_PROTO(Yap_SizeOfBlock,(CODEADDR)); void STD_PROTO(Yap_FreeCodeSpace,(char *)); char *STD_PROTO(Yap_AllocAtomSpace,(unsigned int)); char *STD_PROTO(Yap_AllocCodeSpace,(unsigned int)); diff --git a/H/clause.h b/H/clause.h index ec9f863d8..4cbde92c3 100644 --- a/H/clause.h +++ b/H/clause.h @@ -46,6 +46,7 @@ typedef struct logic_upd_index { /* A lock for manipulating the clause */ lockvar ClLock; #endif + UInt ClSize; union { PredEntry *pred; struct logic_upd_index *ParentIndex; @@ -67,6 +68,7 @@ typedef struct logic_upd_clause { /* A lock for manipulating the clause */ lockvar ClLock; #endif + UInt ClSize; /* extra clause information for logical update indices and facts */ /* indices that may still backtrack to this clause */ UInt ClRefCount; @@ -88,6 +90,7 @@ typedef struct dynamic_clause { /* A lock for manipulating the clause */ lockvar ClLock; #endif + UInt ClSize; UInt ClRefCount; yamop *ClPrevious; /* immediate update clause */ /* The instructions, at least one of the form sl */ @@ -97,6 +100,7 @@ typedef struct dynamic_clause { typedef struct static_index { /* A set of flags describing info on the clause */ CELL ClFlags; + UInt ClSize; struct static_index *SiblingIndex; struct static_index *ChildIndex; /* The instructions, at least one of the form sl */ @@ -107,6 +111,7 @@ typedef struct static_clause { /* A set of flags describing info on the clause */ Functor Id; CELL ClFlags; + UInt ClSize; union { DBTerm *ClSource; PredEntry *ClPred; @@ -118,12 +123,13 @@ typedef struct static_clause { typedef struct dead_clause { CELL ClFlags; - struct dead_clause *NextCl; /* dead clause */ #if defined(YAPOR) || defined(THREADS) /* A lock for manipulating the clause */ lockvar ClLock; UInt ref_count; #endif + UInt ClSize; + struct dead_clause *NextCl; /* dead clause */ } DeadClause; typedef union clause_obj { diff --git a/m4/Yatom.h.m4 b/m4/Yatom.h.m4 index 4ce7390f9..32b91c05d 100644 --- a/m4/Yatom.h.m4 +++ b/m4/Yatom.h.m4 @@ -197,13 +197,13 @@ typedef enum { /* profile data */ typedef struct { -#if defined(YAPOR) || defined(THREADS) - lockvar lock; /* a simple lock to protect this entry */ -#endif YAP_ULONG_LONG NOfEntries; /* nbr of times head unification succeeded*/ YAP_ULONG_LONG NOfHeadSuccesses; /* nbr of times head unification succeeded*/ YAP_ULONG_LONG NOfRetries; /* nbr of times a clause for the pred was retried */ +#if defined(YAPOR) || defined(THREADS) + lockvar lock; /* a simple lock to protect this entry */ +#endif } profile_data; typedef struct pred_entry { @@ -238,10 +238,10 @@ typedef struct pred_entry { tab_ent_ptr TableOfPred; #endif /* TABLING */ Term ModuleOfPred; /* module for this definition */ + struct pred_entry *NextPredOfModule; /* next pred for same module */ /* This must be at an odd number of cells, otherwise it will not be aligned on RISC machines */ profile_data StatisticsForPred; /* enable profiling for predicate */ - struct pred_entry *NextPredOfModule; /* next pred for same module */ } PredEntry; #define PEProp ((PropFlags)(0x0000))