more fixes for USE_SYSTEM_MEMORY

git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1047 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
vsc 2004-04-22 20:07:07 +00:00
parent 38b965d2fa
commit 91f87b3109
11 changed files with 66 additions and 44 deletions

View File

@ -10,8 +10,12 @@
* * * *
* File: absmi.c * * File: absmi.c *
* comments: Portable abstract machine interpreter * * comments: Portable abstract machine interpreter *
* Last rev: $Date: 2004-04-22 03:24:17 $,$Author: vsc $ * * Last rev: $Date: 2004-04-22 20:07:02 $,$Author: vsc $ *
* $Log: not supported by cvs2svn $ * $Log: not supported by cvs2svn $
* Revision 1.130 2004/04/22 03:24:17 vsc
* trust_logical should protect the last clause, otherwise it cannot
* jump there.
*
* Revision 1.129 2004/04/16 19:27:30 vsc * Revision 1.129 2004/04/16 19:27:30 vsc
* more bug fixes * more bug fixes
* *
@ -1221,10 +1225,12 @@ Yap_absmi(int inp)
to dispose of it to dispose of it
*/ */
LOCK(lcl->ClLock); LOCK(lcl->ClLock);
/* make sure the clause isn't destroyed */ if (lcl->ClRefCount == 1) {
/* always add an extra reference */ /* make sure the clause isn't destroyed */
INC_CLREF_COUNT(lcl); /* always add an extra reference */
TRAIL_CLREF(lcl); INC_CLREF_COUNT(lcl);
TRAIL_CLREF(lcl);
}
UNLOCK(cl->ClLock); UNLOCK(cl->ClLock);
} }
Yap_ErLogUpdIndex(cl); Yap_ErLogUpdIndex(cl);
@ -1242,7 +1248,7 @@ Yap_absmi(int inp)
if (next != FAILCODE) { if (next != FAILCODE) {
LogUpdClause *lcl = ClauseCodeToLogUpdClause(next); LogUpdClause *lcl = ClauseCodeToLogUpdClause(next);
/* make sure we don't erase the clause we are jumping too */ /* make sure we don't erase the clause we are jumping too */
if (!(lcl->ClFlags & InUseMask)) { if (lcl->ClRefCount == 1 && !(lcl->ClFlags & InUseMask)) {
lcl->ClFlags |= InUseMask; lcl->ClFlags |= InUseMask;
TRAIL_CLREF(lcl); TRAIL_CLREF(lcl);
} }

View File

@ -12,7 +12,7 @@
* Last rev: * * Last rev: *
* mods: * * mods: *
* comments: allocating space * * comments: allocating space *
* version:$Id: alloc.c,v 1.48 2004-03-05 15:26:32 vsc Exp $ * * version:$Id: alloc.c,v 1.49 2004-04-22 20:07:03 vsc Exp $ *
*************************************************************************/ *************************************************************************/
#ifdef SCCS #ifdef SCCS
static char SccsId[] = "%W% %G%"; static char SccsId[] = "%W% %G%";
@ -114,6 +114,7 @@ Yap_ExpandPreAllocCodeSpace(UInt sz0)
if (!(ptr = realloc(ScratchPad.ptr, sz))) if (!(ptr = realloc(ScratchPad.ptr, sz)))
return NULL; return NULL;
ScratchPad.ptr = ptr;
AuxSp = (CELL *)(AuxTop = ptr+sz); AuxSp = (CELL *)(AuxTop = ptr+sz);
return ptr; return ptr;
} }

View File

@ -11,8 +11,11 @@
* File: amasm.c * * File: amasm.c *
* comments: abstract machine assembler * * comments: abstract machine assembler *
* * * *
* Last rev: $Date: 2004-03-31 01:03:09 $ * * Last rev: $Date: 2004-04-22 20:07:04 $ *
* $Log: not supported by cvs2svn $ * $Log: not supported by cvs2svn $
* Revision 1.59 2004/03/31 01:03:09 vsc
* support expand group of clauses
*
* Revision 1.58 2004/03/10 14:59:55 vsc * Revision 1.58 2004/03/10 14:59:55 vsc
* optimise -> for type tests * optimise -> for type tests
* * * *
@ -435,10 +438,11 @@ a_vv(op_numbers opcode, op_numbers opcodew, yamop *code_p, int pass_no, struct i
} }
cip->cpc = cip->cpc->nextInst; cip->cpc = cip->cpc->nextInst;
if (pass_no) { if (pass_no) {
ve = (Ventry *) cip->cpc->rnd1;
OPREG var_offset; OPREG var_offset;
int is_y_var = (ve->KindOfVE == PermVar); int is_y_var;
ve = (Ventry *) cip->cpc->rnd1;
is_y_var = (ve->KindOfVE == PermVar);
var_offset = Var_Ref(ve, is_y_var); var_offset = Var_Ref(ve, is_y_var);
code_p->u.oxx.xr = emit_xreg(var_offset); code_p->u.oxx.xr = emit_xreg(var_offset);
} }

View File

@ -11,8 +11,11 @@
* File: compiler.c * * File: compiler.c *
* comments: Clause compiler * * comments: Clause compiler *
* * * *
* Last rev: $Date: 2004-03-10 16:27:39 $,$Author: vsc $ * * Last rev: $Date: 2004-04-22 20:07:04 $,$Author: vsc $ *
* $Log: not supported by cvs2svn $ * $Log: not supported by cvs2svn $
* Revision 1.49 2004/03/10 16:27:39 vsc
* skip compilation steps for ground facts.
*
* Revision 1.48 2004/03/08 19:31:01 vsc * Revision 1.48 2004/03/08 19:31:01 vsc
* move to 4.5.3 * move to 4.5.3
* * * *
@ -2732,12 +2735,11 @@ Yap_cclause(Term inp_clause, int NOfArgs, int mod, Term src)
int botch_why; int botch_why;
volatile Term my_clause = inp_clause; volatile Term my_clause = inp_clause;
/* may botch while doing a different module */ /* may botch while doing a different module */
/* first, initialise cglobs->cint.CompilerBotch to handle all cases of interruptions */ /* first, initialise cglobs->cint.CompilerBotch to handle all cases of interruptions */
Yap_ErrorMessage = NULL;
Yap_Error_Size = 0;
compiler_struct cglobs; compiler_struct cglobs;
Yap_ErrorMessage = NULL;
Yap_Error_Size = 0;
if ((botch_why = setjmp(cglobs.cint.CompilerBotch)) == 3) { if ((botch_why = setjmp(cglobs.cint.CompilerBotch)) == 3) {
/* out of local stack, just duplicate the stack */ /* out of local stack, just duplicate the stack */
restore_machine_regs(); restore_machine_regs();

View File

@ -655,6 +655,7 @@ static CELL *MkDBTerm(register CELL *pt0, register CELL *pt0_end,
CELL *ConstraintsBottom = NULL; CELL *ConstraintsBottom = NULL;
CELL *origH = H; CELL *origH = H;
#endif #endif
CELL *CodeMaxBase = CodeMax;
loop: loop:
while (pt0 <= pt0_end) { while (pt0 <= pt0_end) {
@ -981,7 +982,7 @@ static CELL *MkDBTerm(register CELL *pt0, register CELL *pt0_end,
error: error:
Yap_Error_TYPE = OUT_OF_HEAP_ERROR; Yap_Error_TYPE = OUT_OF_HEAP_ERROR;
Yap_Error_Size = 1024+((char *)AuxSp-(char *)HeapTop); Yap_Error_Size = 1024+((char *)AuxSp-(char *)CodeMaxBase);
*vars_foundp = vars_found; *vars_foundp = vars_found;
#ifdef RATIONAL_TREES #ifdef RATIONAL_TREES
while (to_visit > to_visit_base) { while (to_visit > to_visit_base) {

View File

@ -763,7 +763,7 @@ check_global(void) {
#if INSTRUMENT_GC #if INSTRUMENT_GC
if (IsVarTerm(ccurr)) { if (IsVarTerm(ccurr)) {
if (IsBlobFunctor((Functor)ccurr)) vars[gc_num]++; if (IsBlobFunctor((Functor)ccurr)) vars[gc_num]++;
else if (ccurr != 0 && ccurr < (CELL)HeapTop) { else if (ccurr != 0 && (ccurr < (CELL)Yap_GlobalBase || ccurr > (CELL)Yap_TrailTop)) {
/* printf("%p: %s/%d\n", current, /* printf("%p: %s/%d\n", current,
RepAtom(NameOfFunctor((Functor)ccurr))->StrOfAE, RepAtom(NameOfFunctor((Functor)ccurr))->StrOfAE,
ArityOfFunctor((Functor)ccurr));*/ ArityOfFunctor((Functor)ccurr));*/
@ -875,7 +875,7 @@ mark_variable(CELL_PTR current)
} }
goto begin; goto begin;
#ifdef DEBUG #ifdef DEBUG
} else if (next < (CELL *)AtomBase || next < (CELL *)HeapTop) { } else if (next < (CELL *)Yap_GlobalBase || next > (CELL *)Yap_TrailTop) {
fprintf(Yap_stderr, "ooops while marking %lx, %p at %p\n", (unsigned long int)ccur, current, next); fprintf(Yap_stderr, "ooops while marking %lx, %p at %p\n", (unsigned long int)ccur, current, next);
#endif #endif
} else { } else {
@ -1844,7 +1844,8 @@ sweep_trail(choiceptr gc_B, tr_fr_ptr old_TR)
} }
} }
#endif #endif
} else if ((CELL *)trail_cell < (CELL *)HeapTop) { } else if ((CELL *)trail_cell < (CELL *)Yap_GlobalBase ||
(CELL *)trail_cell > (CELL *)Yap_TrailTop) {
/* we may have pointers from the heap back into the cell */ /* we may have pointers from the heap back into the cell */
CELL *next = GET_NEXT(*CellPtr(trail_cell)); CELL *next = GET_NEXT(*CellPtr(trail_cell));
UNMARK(CellPtr(trail_cell)); UNMARK(CellPtr(trail_cell));
@ -1871,7 +1872,7 @@ sweep_trail(choiceptr gc_B, tr_fr_ptr old_TR)
/* process all segments */ /* process all segments */
if ( if (
#ifdef SBA #ifdef SBA
(ADDR) pt0 >= HeapTop (ADDR) pt0 >= Yap_GlobalBase
#else #else
(ADDR) pt0 >= Yap_TrailBase (ADDR) pt0 >= Yap_TrailBase
#endif #endif
@ -2994,6 +2995,7 @@ do_gc(Int predarity, CELL *current_env, yamop *nextop)
int gc_trace = FALSE; int gc_trace = FALSE;
#if USE_SYSTEM_MALLOC #if USE_SYSTEM_MALLOC
/* I can't use it because I may have pointers to high memory */
return 0; return 0;
#endif #endif
#if COROUTINING #if COROUTINING
@ -3050,6 +3052,7 @@ do_gc(Int predarity, CELL *current_env, yamop *nextop)
fprintf(Yap_stderr, "[GC] Trail:%8ld cells (%p-%p)\n", fprintf(Yap_stderr, "[GC] Trail:%8ld cells (%p-%p)\n",
(unsigned long int)(TR-(tr_fr_ptr)Yap_TrailBase),Yap_TrailBase,TR); (unsigned long int)(TR-(tr_fr_ptr)Yap_TrailBase),Yap_TrailBase,TR);
} }
#if !USE_SYSTEM_MALLOC
if (HeapTop >= Yap_GlobalBase - MinHeapGap) { if (HeapTop >= Yap_GlobalBase - MinHeapGap) {
*--ASP = (CELL)current_env; *--ASP = (CELL)current_env;
if (!Yap_growheap(FALSE, MinHeapGap, NULL)) { if (!Yap_growheap(FALSE, MinHeapGap, NULL)) {
@ -3059,6 +3062,7 @@ do_gc(Int predarity, CELL *current_env, yamop *nextop)
current_env = (CELL *)*ASP; current_env = (CELL *)*ASP;
ASP++; ASP++;
} }
#endif
time_start = Yap_cputime(); time_start = Yap_cputime();
total_marked = 0; total_marked = 0;
#ifdef COROUTING #ifdef COROUTING

View File

@ -86,7 +86,7 @@ copy_complex_term(register CELL *pt0, register CELL *pt0_end, CELL *ptf, CELL *H
*ptf = AbsPair(H); *ptf = AbsPair(H);
ptf++; ptf++;
#ifdef RATIONAL_TREES #ifdef RATIONAL_TREES
if (to_visit + 4 >= (CELL **)Yap_GlobalBase) { if (to_visit + 4 >= (CELL **)AuxSp) {
goto heap_overflow; goto heap_overflow;
} }
to_visit[0] = pt0; to_visit[0] = pt0;
@ -98,7 +98,7 @@ copy_complex_term(register CELL *pt0, register CELL *pt0_end, CELL *ptf, CELL *H
to_visit += 4; to_visit += 4;
#else #else
if (pt0 < pt0_end) { if (pt0 < pt0_end) {
if (to_visit + 3 >= (CELL **)Yap_GlobalBase) { if (to_visit + 3 >= (CELL **)AuxSp) {
goto heap_overflow; goto heap_overflow;
} }
to_visit[0] = pt0; to_visit[0] = pt0;
@ -136,7 +136,7 @@ copy_complex_term(register CELL *pt0, register CELL *pt0_end, CELL *ptf, CELL *H
ptf++; ptf++;
/* store the terms to visit */ /* store the terms to visit */
#ifdef RATIONAL_TREES #ifdef RATIONAL_TREES
if (to_visit + 4 >= (CELL **)Yap_GlobalBase) { if (to_visit + 4 >= (CELL **)AuxSp) {
goto heap_overflow; goto heap_overflow;
} }
to_visit[0] = pt0; to_visit[0] = pt0;
@ -148,7 +148,7 @@ copy_complex_term(register CELL *pt0, register CELL *pt0_end, CELL *ptf, CELL *H
to_visit += 4; to_visit += 4;
#else #else
if (pt0 < pt0_end) { if (pt0 < pt0_end) {
if (to_visit + 3 >= (CELL **)Yap_GlobalBase) { if (to_visit + 3 >= (CELL **)AuxSp) {
goto heap_overflow; goto heap_overflow;
} }
to_visit[0] = pt0; to_visit[0] = pt0;
@ -335,8 +335,8 @@ CopyTerm(Term inp) {
t = Deref(ARG1); t = Deref(ARG1);
goto restart_attached; goto restart_attached;
} else { /* handle overflow */ } else { /* handle overflow */
if (!Yap_growheap(FALSE, 0, NULL)) { if (!Yap_ExpandPreAllocCodeSpace(0)) {
Yap_Error(SYSTEM_ERROR, TermNil, Yap_ErrorMessage); Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
return(FALSE); return(FALSE);
} }
t = Deref(ARG1); t = Deref(ARG1);
@ -371,8 +371,8 @@ CopyTerm(Term inp) {
t = Deref(ARG1); t = Deref(ARG1);
goto restart_list; goto restart_list;
} else { /* handle overflow */ } else { /* handle overflow */
if (!Yap_growheap(FALSE, 0, NULL)) { if (!Yap_ExpandPreAllocCodeSpace(0)) {
Yap_Error(SYSTEM_ERROR, TermNil, Yap_ErrorMessage); Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
return(FALSE); return(FALSE);
} }
t = Deref(ARG1); t = Deref(ARG1);
@ -406,8 +406,8 @@ CopyTerm(Term inp) {
t = Deref(ARG1); t = Deref(ARG1);
goto restart_appl; goto restart_appl;
} else { /* handle overflow */ } else { /* handle overflow */
if (!Yap_growheap(FALSE, 0, NULL)) { if (!Yap_ExpandPreAllocCodeSpace(0)) {
Yap_Error(SYSTEM_ERROR, TermNil, Yap_ErrorMessage); Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
return(FALSE); return(FALSE);
} }
t = Deref(ARG1); t = Deref(ARG1);
@ -459,7 +459,7 @@ static int copy_complex_term_no_delays(register CELL *pt0, register CELL *pt0_en
*ptf = AbsPair(H); *ptf = AbsPair(H);
ptf++; ptf++;
#ifdef RATIONAL_TREES #ifdef RATIONAL_TREES
if (to_visit + 4 >= (CELL **)Yap_GlobalBase) { if (to_visit + 4 >= (CELL **)AuxSp) {
goto heap_overflow; goto heap_overflow;
} }
to_visit[0] = pt0; to_visit[0] = pt0;
@ -471,7 +471,7 @@ static int copy_complex_term_no_delays(register CELL *pt0, register CELL *pt0_en
to_visit += 4; to_visit += 4;
#else #else
if (pt0 < pt0_end) { if (pt0 < pt0_end) {
if (to_visit + 3 >= (CELL **)Yap_GlobalBase) { if (to_visit + 3 >= (CELL **)AuxSp) {
goto heap_overflow; goto heap_overflow;
} }
to_visit[0] = pt0; to_visit[0] = pt0;
@ -507,7 +507,7 @@ static int copy_complex_term_no_delays(register CELL *pt0, register CELL *pt0_en
ptf++; ptf++;
/* store the terms to visit */ /* store the terms to visit */
#ifdef RATIONAL_TREES #ifdef RATIONAL_TREES
if (to_visit + 4 >= (CELL **)Yap_GlobalBase) { if (to_visit + 4 >= (CELL **)AuxSp) {
goto heap_overflow; goto heap_overflow;
} }
to_visit[0] = pt0; to_visit[0] = pt0;
@ -518,7 +518,7 @@ static int copy_complex_term_no_delays(register CELL *pt0, register CELL *pt0_en
*pt0 = AbsAppl(H); *pt0 = AbsAppl(H);
to_visit += 4; to_visit += 4;
#else #else
if (to_visit + 3 >= (CELL **)Yap_GlobalBase) { if (to_visit + 3 >= (CELL **)AuxSp) {
goto heap_overflow; goto heap_overflow;
} }
if (pt0 < pt0_end) { if (pt0 < pt0_end) {
@ -645,8 +645,8 @@ CopyTermNoDelays(Term inp) {
t = Deref(ARG1); t = Deref(ARG1);
goto restart_list; goto restart_list;
} else { /* handle overflow */ } else { /* handle overflow */
if (!Yap_growheap(FALSE, 0, NULL)) { if (!Yap_ExpandPreAllocCodeSpace(0)) {
Yap_Error(SYSTEM_ERROR, TermNil, Yap_ErrorMessage); Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
return(FALSE); return(FALSE);
} }
t = Deref(ARG1); t = Deref(ARG1);
@ -677,8 +677,8 @@ CopyTermNoDelays(Term inp) {
t = Deref(ARG1); t = Deref(ARG1);
goto restart_appl; goto restart_appl;
} else { /* handle overflow */ } else { /* handle overflow */
if (!Yap_growheap(FALSE, 0, NULL)) { if (!Yap_ExpandPreAllocCodeSpace(0)) {
Yap_Error(SYSTEM_ERROR, TermNil, Yap_ErrorMessage); Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
return(FALSE); return(FALSE);
} }
t = Deref(ARG1); t = Deref(ARG1);

View File

@ -10,7 +10,7 @@
* File: Heap.h * * File: Heap.h *
* mods: * * mods: *
* comments: Heap Init Structure * * comments: Heap Init Structure *
* version: $Id: Heap.h,v 1.61 2004-03-02 16:44:55 vsc Exp $ * * version: $Id: Heap.h,v 1.62 2004-04-22 20:07:05 vsc Exp $ *
*************************************************************************/ *************************************************************************/
/* information that can be stored in Code Space */ /* information that can be stored in Code Space */
@ -402,7 +402,7 @@ typedef struct various_codes {
AtomHashEntry *hash_chain; AtomHashEntry *hash_chain;
} all_heap_codes; } all_heap_codes;
#ifdef THREADS #ifdef USE_SYSTEM_MALLOC
struct various_codes *heap_regs; struct various_codes *heap_regs;
#else #else
#define heap_regs ((all_heap_codes *)HEAP_INIT_BASE) #define heap_regs ((all_heap_codes *)HEAP_INIT_BASE)
@ -719,7 +719,7 @@ struct various_codes *heap_regs;
ADDR STD_PROTO(Yap_ExpandPreAllocCodeSpace, (UInt)); ADDR STD_PROTO(Yap_ExpandPreAllocCodeSpace, (UInt));
#define Yap_ReleasePreAllocCodeSpace(x) #define Yap_ReleasePreAllocCodeSpace(x)
#if defined(YAPOR) || defined(THREADS) #if USE_SYSTEM_MALLOC
ADDR STD_PROTO(Yap_InitPreAllocCodeSpace, (void)); ADDR STD_PROTO(Yap_InitPreAllocCodeSpace, (void));
EXTERN inline ADDR EXTERN inline ADDR
Yap_PreAllocCodeSpace(void) Yap_PreAllocCodeSpace(void)

View File

@ -51,7 +51,11 @@
#define ONHEAP(ptr) (CellPtr(ptr) >= H0 && CellPtr(ptr) < H) #define ONHEAP(ptr) (CellPtr(ptr) >= H0 && CellPtr(ptr) < H)
/* is ptr a pointer to code space? */ /* is ptr a pointer to code space? */
#if USE_SYSTEM_MALLOC
#define ONCODE(ptr) (Addr(ptr) < Yap_GlobalBase || Addr(ptr) > Yap_TrailTop)
#else
#define ONCODE(ptr) (Addr(ptr) < HeapTop && Addr(ptr) >= Yap_HeapBase) #define ONCODE(ptr) (Addr(ptr) < HeapTop && Addr(ptr) >= Yap_HeapBase)
#endif
/* is val pointing to something bound to the heap? */ /* is val pointing to something bound to the heap? */

View File

@ -10,10 +10,10 @@
* File: TermExt.h * * File: TermExt.h *
* mods: * * mods: *
* comments: Extensions to standard terms for YAP * * comments: Extensions to standard terms for YAP *
* version: $Id: TermExt.h.m4,v 1.12 2004-01-23 02:23:12 vsc Exp $ * * version: $Id: TermExt.h.m4,v 1.13 2004-04-22 20:07:06 vsc Exp $ *
*************************************************************************/ *************************************************************************/
#ifdef THREADS #ifdef USE_SYSTEM_MALLOC
#define SF_STORE (&(heap_regs->funcs)) #define SF_STORE (&(heap_regs->funcs))
#else #else
#define SF_STORE ((special_functors *)HEAP_INIT_BASE) #define SF_STORE ((special_functors *)HEAP_INIT_BASE)

View File

@ -10,7 +10,7 @@
* File: Yap.h.m4 * * File: Yap.h.m4 *
* mods: * * mods: *
* comments: main header file for YAP * * comments: main header file for YAP *
* version: $Id: Yap.h.m4,v 1.56 2004-03-08 19:31:01 vsc Exp $ * * version: $Id: Yap.h.m4,v 1.57 2004-04-22 20:07:07 vsc Exp $ *
*************************************************************************/ *************************************************************************/
#include "config.h" #include "config.h"
@ -255,7 +255,7 @@ extern char Yap_Option[20];
#elif mips #elif mips
#define MMAP_ADDR 0x02000000 #define MMAP_ADDR 0x02000000
#elif __APPLE__ #elif __APPLE__
#define MMAP_ADDR 0x01000000 #define MMAP_ADDR 0x20000000
#else #else
#define MMAP_ADDR 0x09000000 #define MMAP_ADDR 0x09000000
#endif #endif