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
This commit is contained in:
vsc 2006-05-19 14:31:32 +00:00
parent ba3ea30e8e
commit eea9f2a58e
17 changed files with 38 additions and 237 deletions

View File

@ -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:
{

View File

@ -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

View File

@ -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<dim;i++) {
if (ar1[i]-ar2[i])
return ar1[i]-ar2[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;i<dim;i++) {
if (ar1[i]-ar2[i])
return ar1[i]-ar2[i];
}
return 0;
} else {
return 1;
}
}
case db_ref_e:
if (IsRefTerm(t2))
return Unsigned(RefOfTerm(t2)) -
@ -450,9 +399,6 @@ compare(Term t1, Term t2) /* compare terms t1 and t2 */
Int r;
if (IsExtensionFunctor(fun2)) {
if (fun2 == FunctorDoubleArray ||
fun2 == FunctorIntArray)
return -1;
return 1;
}
r = ArityOfFunctor(fun1) - ArityOfFunctor(fun2);

View File

@ -11,8 +11,11 @@
* File: compiler.c *
* comments: Clause compiler *
* *
* Last rev: $Date: 2006-05-19 13:48:11 $,$Author: vsc $ *
* Last rev: $Date: 2006-05-19 14:31:31 $,$Author: vsc $ *
* $Log: not supported by cvs2svn $
* Revision 1.76 2006/05/19 13:48:11 vsc
* help to make Yap work with dynamic libs
*
* Revision 1.75 2006/05/16 18:37:30 vsc
* WIN32 fixes
* compiler bug fixes
@ -546,13 +549,6 @@ c_arg(Int argno, Term t, unsigned int arity, unsigned int level, compiler_struct
Yap_emit((cglobs->onhead ? (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

View File

@ -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:

View File

@ -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;

View File

@ -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++;
}

View File

@ -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:
{

View File

@ -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);

View File

@ -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);

View File

@ -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;

View File

@ -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));

View File

@ -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]);

View File

@ -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;

View File

@ -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

View File

@ -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 <stdio.h>
@ -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]);

View File

@ -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)