From eea9f2a58ecb9cf68b073fb1a00c853c3654da82 Mon Sep 17 00:00:00 2001 From: vsc Date: Fri, 19 May 2006 14:31:32 +0000 Subject: [PATCH] get rid of IntArrays and FloatArray code. include holes when calculating memory usage. git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1640 b08c6af1-5177-4d33-ba66-4b1c6b8b522a --- C/agc.c | 4 --- C/alloc.c | 8 +++++- C/cmppreds.c | 54 ----------------------------------- C/compiler.c | 12 +++----- C/corout.c | 4 --- C/dbase.c | 26 ----------------- C/dlmalloc.c | 1 + C/grow.c | 12 -------- C/heapgc.c | 37 ------------------------ C/inlines.c | 3 -- C/save.c | 6 ++++ C/stdpreds.c | 13 +++++---- C/unify.c | 6 ---- C/write.c | 2 -- H/Heap.h | 4 ++- H/TermExt.h | 79 ++++++---------------------------------------------- H/alloc.h | 4 --- 17 files changed, 38 insertions(+), 237 deletions(-) diff --git a/C/agc.c b/C/agc.c index fd1c2845c..36816fff8 100644 --- a/C/agc.c +++ b/C/agc.c @@ -252,10 +252,6 @@ mark_global_cell(CELL *pt) #else return pt + 3; #endif - case (CELL)FunctorIntArray: - return pt + (4+pt[1]); - case (CELL)FunctorDoubleArray: - return pt + (4+((SIZEOF_DOUBLE -SIZEOF_LONG_INT) + pt[1]*SIZEOF_DOUBLE)/SIZEOF_LONG_INT); #if USE_GMP case (CELL)FunctorBigInt: { diff --git a/C/alloc.c b/C/alloc.c index 1bfb0c836..219caea97 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.85 2006-05-18 16:33:04 vsc Exp $ * +* version:$Id: alloc.c,v 1.86 2006-05-19 14:31:31 vsc Exp $ * *************************************************************************/ #ifdef SCCS static char SccsId[] = "%W% %G%"; @@ -61,6 +61,11 @@ static char SccsId[] = "%W% %G%"; #define malloc Yap_dlmalloc #define free Yap_dlfree #define realloc Yap_dlrealloc +#else +void Yap_add_memory_hole(ADDR Start, ADDR End) +{ + Yap_HoleSize += Start-End; +} #endif #if USE_SYSTEM_MALLOC||USE_DL_MALLOC @@ -1322,6 +1327,7 @@ InitHeap(void *heap_addr) /* reserve space for specially allocated functors and atoms so that their values can be known statically */ HeapTop = Yap_HeapBase + AdjustSize(sizeof(all_heap_codes)); + Yap_HoleSize = 0; #if USE_DL_MALLOC Yap_initdlmalloc(); #else diff --git a/C/cmppreds.c b/C/cmppreds.c index a92c64fec..b9944a247 100644 --- a/C/cmppreds.c +++ b/C/cmppreds.c @@ -377,57 +377,6 @@ compare(Term t1, Term t2) /* compare terms t1 and t2 */ return -1; } #endif - case int_array_e: - { - Functor f2; - - if (!IsApplTerm(t2)) - return 1; - f2 = FunctorOfTerm(t2); - if (f2 == FunctorDoubleArray) { - UInt dim, i; - Int *ar1, *ar2; - - if ((dim = Yap_SizeOfIntArray(t1)) != Yap_SizeOfIntArray(t2)) { - return dim-Yap_SizeOfIntArray(t2); - } - ar1 = Yap_IntArrayOfTerm(t1); - ar2 = Yap_IntArrayOfTerm(t2); - for (i=0;i 0; - } - return 0; - } else if (f2 == FunctorIntArray) { - return -1; - } else - return 1; - } - case double_array_e: - { - Functor f2; - - if (!IsApplTerm(t2)) - return 1; - f2 = FunctorOfTerm(t2); - if (f2 == FunctorDoubleArray) { - UInt dim, i; - Float *ar1, *ar2; - - if ((dim = Yap_SizeOfFloatArray(t1)) != Yap_SizeOfFloatArray(t2)) { - return dim-Yap_SizeOfFloatArray(t2); - } - ar1 = Yap_FloatArrayOfTerm(t1); - ar2 = Yap_FloatArrayOfTerm(t2); - for (i=0;ionhead ? (argno == (Int)arity ? unify_last_atom_op : unify_atom_op) : write_atom_op), (CELL) t, Zero, &cglobs->cint); - } else if (Yap_IsIntArrayTerm(t) || Yap_IsFloatArrayTerm(t)) { - Yap_Error_TYPE = TYPE_ERROR_NUMBER; - Yap_Error_Term = t; - Yap_ErrorMessage = Yap_ErrorSay; - sprintf(Yap_ErrorMessage, "compiling array term"); - save_machine_regs(); - longjmp(cglobs->cint.CompilerBotch,1); } else if (IsIntegerTerm(t) || IsFloatTerm(t) || IsBigIntTerm(t)) { if (!IsIntTerm(t)) { /* we are taking a blob, that is a binary that is supposed to be diff --git a/C/corout.c b/C/corout.c index 8bb1696a8..71175f0ee 100644 --- a/C/corout.c +++ b/C/corout.c @@ -198,8 +198,6 @@ static int can_unify_complex(register CELL *pt0, if (IsExtensionFunctor(f)) { switch((CELL)f) { case (CELL)FunctorDBRef: - case (CELL)FunctorIntArray: - case (CELL)FunctorDoubleArray: if (d0 == d1) continue; goto comparison_failed; case (CELL)FunctorLongInt: @@ -339,8 +337,6 @@ can_unify(Term t1, Term t2, Term *Vars) if (IsExtensionFunctor(f)) { switch((CELL)f) { case (CELL)FunctorDBRef: - case (CELL)FunctorIntArray: - case (CELL)FunctorDoubleArray: if (t1 == t2) return FALSE; return FALSE; case (CELL)FunctorLongInt: diff --git a/C/dbase.c b/C/dbase.c index 964763731..a1d29459b 100644 --- a/C/dbase.c +++ b/C/dbase.c @@ -796,26 +796,6 @@ static CELL *MkDBTerm(register CELL *pt0, register CELL *pt0_end, CodeMax = copy_long_int(CodeMax, ap2); ++pt0; continue; - case (CELL)FunctorIntArray: - CheckDBOverflow(4+Yap_SizeOfIntArray(d0)); -#ifdef IDB_USE_MBIT - *StoPoint++ = AbsAppl(CodeMax)|MBIT; -#else - *StoPoint++ = AbsAppl(CodeMax); -#endif - CodeMax = copy_int_array(CodeMax, ap2); - ++pt0; - continue; - case (CELL)FunctorDoubleArray: - CheckDBOverflow(4+Yap_SizeOfFloatArray(d0)); -#ifdef IDB_USE_MBIT - *StoPoint++ = AbsAppl(CodeMax)|MBIT; -#else - *StoPoint++ = AbsAppl(CodeMax); -#endif - CodeMax = copy_double_array(CodeMax, ap2); - ++pt0; - continue; #ifdef USE_GMP case (CELL)FunctorBigInt: CheckDBOverflow(2+Yap_SizeOfBigInt(d0)); @@ -1559,12 +1539,6 @@ CreateDBStruct(Term Tm, DBProp p, int InFlag, int *pstat, UInt extra_size, struc fun = FunctorOfTerm(Tm); if (IsExtensionFunctor(fun)) { switch((CELL)fun) { - case (CELL)FunctorIntArray: - ntp = copy_int_array(ntp0, RepAppl(Tm)); - break; - case (CELL)FunctorDoubleArray: - ntp = copy_double_array(ntp0, RepAppl(Tm)); - break; case (CELL)FunctorDouble: ntp = copy_double(ntp0, RepAppl(Tm)); break; diff --git a/C/dlmalloc.c b/C/dlmalloc.c index be353edf5..9a3315dd0 100755 --- a/C/dlmalloc.c +++ b/C/dlmalloc.c @@ -185,6 +185,7 @@ Yap_add_memory_hole(ADDR start, ADDR end) } Yap_MemoryHoles[Yap_NOfMemoryHoles].start = start; Yap_MemoryHoles[Yap_NOfMemoryHoles].end = end; + Yap_HoleSize += start-end; Yap_NOfMemoryHoles++; } diff --git a/C/grow.c b/C/grow.c index 2df7e6f34..437f77640 100644 --- a/C/grow.c +++ b/C/grow.c @@ -485,18 +485,6 @@ AdjustGlobal(void) pt += 2; #endif break; - case (CELL)FunctorDoubleArray: - { - Int sz = 3+(SIZEOF_DOUBLE-SIZEOF_LONG_INT)/SIZEOF_LONG_INT+pt[0]; - pt += sz; - } - break; - case (CELL)FunctorIntArray: - { - Int sz = 3+pt[0]; - pt += sz; - } - break; #if USE_GMP case (CELL)FunctorBigInt: { diff --git a/C/heapgc.c b/C/heapgc.c index 731b1ed33..a1b8538c5 100644 --- a/C/heapgc.c +++ b/C/heapgc.c @@ -1277,43 +1277,6 @@ mark_variable(CELL_PTR current) MARK(next+2); #endif POP_CONTINUATION(); - case (CELL)FunctorIntArray: - MARK(next); - /* size is given by functor + friends */ - if (next < HGEN) { - total_oldies+=4+next[1]; - } - total_marked += 4+next[1]; - { - int i; - for (i = 0; i <= 4+next[1]; i++) { - PUSH_POINTER(next+i); - } -#if GC_NO_TAGS - MARK(next+(3+next[1])); -#endif - } - POP_CONTINUATION(); - case (CELL)FunctorDoubleArray: - MARK(next); - { - UInt sz = 4+next[1]+(SIZEOF_DOUBLE-SIZEOF_LONG_INT); - /* size is given by functor + friends */ - if (next < HGEN) { - total_oldies+=sz; - } - total_marked += sz; - { - int i; - for (i = 0; i <= sz; i++) { - PUSH_POINTER(next+i); - } -#if GC_NO_TAGS - MARK(next+(sz-1)); -#endif - } - } - POP_CONTINUATION(); #ifdef USE_GMP case (CELL)FunctorBigInt: MARK(next); diff --git a/C/inlines.c b/C/inlines.c index 80c8f05bf..3fb162a15 100755 --- a/C/inlines.c +++ b/C/inlines.c @@ -319,9 +319,6 @@ p_eq(void) return (d0 == d1); case (CELL)FunctorLongInt: return(LongIntOfTerm(d0) == LongIntOfTerm(d1)); - case (CELL)FunctorIntArray: - case (CELL)FunctorDoubleArray: - return !Yap_compare_terms(d0,d1); #ifdef USE_GMP case (CELL)FunctorBigInt: return (mpz_cmp(Yap_BigIntOfTerm(d0), Yap_BigIntOfTerm(d1)) == 0); diff --git a/C/save.c b/C/save.c index fa228b3e0..c53722110 100644 --- a/C/save.c +++ b/C/save.c @@ -545,6 +545,12 @@ do_save(int mode) { NewFileInfo('YAPS', 'MYap'); #endif Term t1 = Deref(ARG1); + + if (Yap_HoleSize) { + Yap_Error(SYSTEM_ERROR,MkAtomTerm(Yap_LookupAtom(Yap_FileNameBuf)), + "restore/1: address space has holes, cannot save"); + return FALSE; + } if (!Yap_GetName(Yap_FileNameBuf, YAP_FILENAME_MAX, t1)) { Yap_Error(TYPE_ERROR_LIST,t1,"save/1"); return FALSE; diff --git a/C/stdpreds.c b/C/stdpreds.c index 7e7058810..33fbbee88 100644 --- a/C/stdpreds.c +++ b/C/stdpreds.c @@ -11,8 +11,11 @@ * File: stdpreds.c * * comments: General-purpose C implemented system predicates * * * -* Last rev: $Date: 2006-05-18 16:33:05 $,$Author: vsc $ * +* Last rev: $Date: 2006-05-19 14:31:32 $,$Author: vsc $ * * $Log: not supported by cvs2svn $ +* Revision 1.103 2006/05/18 16:33:05 vsc +* fix info reported by memory manager under DL_MALLOC and SYSTEM_MALLOC +* * Revision 1.102 2006/04/28 17:53:44 vsc * fix the expand_consult patch * @@ -2294,10 +2297,10 @@ Yap_show_statistics(void) #if USE_SYSTEM_MALLOC && HAVE_MALLINFO struct mallinfo mi = mallinfo(); - heap_space_taken = mi.arena+mi.hblkhd; + heap_space_taken = (mi.arena+mi.hblkhd)-Yap_HoleSize; #else heap_space_taken = - (unsigned long int)(Unsigned(HeapTop)-Unsigned(Yap_HeapBase)); + (unsigned long int)(Unsigned(HeapTop)-Unsigned(Yap_HeapBase))-Yap_HoleSize; #endif frag = (100.0*(heap_space_taken-HeapUsed))/heap_space_taken; @@ -2464,9 +2467,9 @@ p_statistics_heap_info(void) #if USE_SYSTEM_MALLOC && HAVE_MALLINFO struct mallinfo mi = mallinfo(); - Term tmax = MkIntegerTerm(mi.arena+mi.hblkhd); + Term tmax = MkIntegerTerm((mi.arena+mi.hblkhd)-Yap_HoleSize); #else - Term tmax = MkIntegerTerm(Unsigned(H0) - Unsigned(Yap_HeapBase)); + Term tmax = MkIntegerTerm((Unsigned(H0) - Unsigned(Yap_HeapBase))-Yap_HoleSize); #endif return(Yap_unify(tmax, ARG1) && Yap_unify(tusage,ARG2)); diff --git a/C/unify.c b/C/unify.c index 1b5948e19..9a5a3c959 100644 --- a/C/unify.c +++ b/C/unify.c @@ -227,8 +227,6 @@ OCUnify_complex(register CELL *pt0, register CELL *pt0_end, if (IsExtensionFunctor(f)) { switch((CELL)f) { case (CELL)FunctorDBRef: - case (CELL)FunctorIntArray: - case (CELL)FunctorDoubleArray: if (d0 == d1) continue; goto cufail; case (CELL)FunctorLongInt: @@ -387,8 +385,6 @@ oc_unify_nvar_nvar: if (IsExtensionFunctor((Functor)d0)) { switch(d0) { case (CELL)FunctorDBRef: - case (CELL)FunctorIntArray: - case (CELL)FunctorDoubleArray: return(pt0 == pt1); case (CELL)FunctorLongInt: return(pt0[1] == pt1[1]); @@ -530,8 +526,6 @@ unify_nvar_nvar: if (IsExtensionFunctor((Functor)d0)) { switch(d0) { case (CELL)FunctorDBRef: - case (CELL)FunctorIntArray: - case (CELL)FunctorDoubleArray: return(pt0 == pt1); case (CELL)FunctorLongInt: return(pt0[1] == pt1[1]); diff --git a/C/write.c b/C/write.c index cde3a8aed..93c75a8e8 100644 --- a/C/write.c +++ b/C/write.c @@ -442,8 +442,6 @@ writeTerm(Term t, int p, int depth, int rinfixarg, struct write_globs *wglb) case (CELL)FunctorDouble: wrputf(FloatOfTerm(t),wglb->writech); return; - case (CELL)FunctorIntArray: - case (CELL)FunctorDoubleArray: case (CELL)FunctorDBRef: wrputref(RefOfTerm(t), wglb->Quote_illegal, wglb->writech); return; diff --git a/H/Heap.h b/H/Heap.h index bef2077f2..d9f890a54 100644 --- a/H/Heap.h +++ b/H/Heap.h @@ -10,7 +10,7 @@ * File: Heap.h * * mods: * * comments: Heap Init Structure * -* version: $Id: Heap.h,v 1.100 2006-05-18 16:33:05 vsc Exp $ * +* version: $Id: Heap.h,v 1.101 2006-05-19 14:31:32 vsc Exp $ * *************************************************************************/ /* information that can be stored in Code Space */ @@ -190,6 +190,7 @@ typedef int (*Agc_hook)(Atom); typedef struct various_codes { special_functors funcs; + UInt hole_size; struct malloc_state *av_; #if USE_DL_MALLOC struct memory_hole memory_holes[MAX_DLMALLOC_HOLES]; @@ -540,6 +541,7 @@ struct various_codes *Yap_heap_regs; #define Yap_heap_regs ((all_heap_codes *)HEAP_INIT_BASE) #endif +#define Yap_HoleSize Yap_heap_regs->hole_size #define Yap_av Yap_heap_regs->av_ #define Yap_MemoryHoles Yap_heap_regs->memory_holes #define Yap_NOfMemoryHoles Yap_heap_regs->nof_memory_holes diff --git a/H/TermExt.h b/H/TermExt.h index 17ba2e4b9..d72d5ceb1 100644 --- a/H/TermExt.h +++ b/H/TermExt.h @@ -10,7 +10,7 @@ * File: TermExt.h * * mods: * * comments: Extensions to standard terms for YAP * -* version: $Id: TermExt.h,v 1.8 2006-05-19 13:48:11 vsc Exp $ * +* version: $Id: TermExt.h,v 1.9 2006-05-19 14:31:32 vsc Exp $ * *************************************************************************/ #ifdef USE_SYSTEM_MALLOC @@ -45,33 +45,27 @@ typedef enum { #if defined(IN_SECOND_QUADRANT) && !GC_NO_TAGS db_ref_e = sizeof (Functor *) | RBIT, - int_array_e = 2 * sizeof (Functor *) | RBIT, - double_array_e = 3 * sizeof (Functor *) | RBIT, - long_int_e = 4 * sizeof (Functor *) | RBIT, + long_int_e = 2 * sizeof (Functor *) | RBIT, #ifdef USE_GMP - big_int_e = 5 * sizeof (Functor *) | RBIT, - double_e = 6 * sizeof (Functor *) | RBIT + big_int_e = 3 * sizeof (Functor *) | RBIT, + double_e = 4 * sizeof (Functor *) | RBIT #else - double_e = 5 * sizeof (Functor *) | RBIT + double_e = 3 * sizeof (Functor *) | RBIT #endif #else db_ref_e = sizeof (Functor *), - int_array_e = 2 * sizeof (Functor *), - double_array_e = 3 * sizeof (Functor *), - long_int_e = 4 * sizeof (Functor *), + long_int_e = 2 * sizeof (Functor *), #ifdef USE_GMP - big_int_e = 5 * sizeof (Functor *), - double_e = 6 * sizeof (Functor *) + big_int_e = 3 * sizeof (Functor *), + double_e = 4 * sizeof (Functor *) #else - double_e = 5 * sizeof (Functor *) + double_e = 3 * sizeof (Functor *) #endif #endif } blob_type; #define FunctorDBRef ((Functor)(db_ref_e)) -#define FunctorIntArray ((Functor)(int_array_e)) -#define FunctorDoubleArray ((Functor)(double_array_e)) #define FunctorLongInt ((Functor)(long_int_e)) #ifdef USE_GMP #define FunctorBigInt ((Functor)(big_int_e)) @@ -326,59 +320,6 @@ IsLongIntTerm (Term t) } -Term Yap_MkIntArrayTerm (UInt, Int *); - -inline EXTERN Int *Yap_IntArrayOfTerm (Term t); - -inline EXTERN Int * -Yap_IntArrayOfTerm (Term t) -{ - return (Int *) (RepAppl(t)+2); -} - -inline EXTERN UInt Yap_SizeOfIntArray (Term t); - -inline EXTERN UInt -Yap_SizeOfIntArray (Term t) -{ - return (UInt) (RepAppl(t)[1]); -} - -inline EXTERN int Yap_IsIntArrayTerm (Term); - -inline EXTERN int -Yap_IsIntArrayTerm (Term t) -{ - return (int) (IsApplTerm (t) && FunctorOfTerm (t) == FunctorIntArray); -} - - -Term Yap_MkFloatArrayTerm (UInt, Float *); - -inline EXTERN Float *Yap_FloatArrayOfTerm (Term t); - -inline EXTERN Float * -Yap_FloatArrayOfTerm (Term t) -{ - return (Float *) (RepAppl(t)+2); -} - -inline EXTERN UInt Yap_SizeOfFloatArray (Term t); - -inline EXTERN UInt -Yap_SizeOfFloatArray (Term t) -{ - return (UInt) (RepAppl(t)[1]); -} - -inline EXTERN int Yap_IsFloatArrayTerm (Term); - -inline EXTERN int -Yap_IsFloatArrayTerm (Term t) -{ - return (int) (IsApplTerm (t) && FunctorOfTerm (t) == FunctorDoubleArray); -} - #ifdef USE_GMP #include @@ -607,8 +548,6 @@ unify_extension (Functor f, CELL d0, CELL * pt0, CELL d1) switch (BlobOfFunctor (f)) { case db_ref_e: - case int_array_e: - case double_array_e: return (d0 == d1); case long_int_e: return (pt0[1] == RepAppl (d1)[1]); diff --git a/H/alloc.h b/H/alloc.h index d43ccaa48..218003fd5 100644 --- a/H/alloc.h +++ b/H/alloc.h @@ -131,11 +131,7 @@ MALLOC_T calloc(size_t,size_t); #endif -#if USE_DL_MALLOC void Yap_add_memory_hole(ADDR, ADDR); -#else -#define Yap_add_memory_hole(Start, End) -#endif #define SCRATCH_START_SIZE (64*1024L) #define SCRATCH_INC_SIZE (64*1024L)