From 46a32fbd832ec58a97c4318ba017286f52830ef6 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Fri, 14 Sep 2018 17:43:36 +0100 Subject: [PATCH] heap --- C/alloc.c | 16 ++++++++++++++++ C/arith0.c | 3 ++- C/qlyr.c | 5 +++++ H/alloc.h | 19 ++++++++++--------- packages/python/pypreds.c | 2 +- 5 files changed, 34 insertions(+), 11 deletions(-) diff --git a/C/alloc.c b/C/alloc.c index 165b32ad3..cdddf9923 100644 --- a/C/alloc.c +++ b/C/alloc.c @@ -42,6 +42,12 @@ static char SccsId[] = "%W% %G%"; #if HAVE_FCNTL_H #include #endif +#if HAVE_SYS_TIME_H +#include +#endif +#if HAVE_SYS_RESOURCE_H +#include +#endif #if HAVE_SYS_STAT_H #include #endif @@ -383,6 +389,16 @@ void Yap_InitHeap(void *heap_addr) { HeapMax = 0; } +// get an approximation to total memory data-base size. + size_t Yap_HeapUsed(void) +{ + #if HAVE_MALLINFO + struct mallinfo mi = mallinfo(); + return mi.uordblks - (LOCAL_TrailTop-LOCAL_GlobalBase); +#endif + return Yap_ClauseSpace+Yap_IndexSpace_Tree+Yap_LUClauseSpace+Yap_LUIndexSpace_CP; +} + static void InitExStacks(int wid, int Trail, int Stack) { CACHE_REGS UInt pm, sa; diff --git a/C/arith0.c b/C/arith0.c index f67e8797b..ea7d3530b 100644 --- a/C/arith0.c +++ b/C/arith0.c @@ -112,6 +112,7 @@ static char SccsId[] = "%W% %G%"; #include "Yatom.h" #include "YapHeap.h" #include "YapEval.h" +#include "alloc.h" @@ -174,7 +175,7 @@ eval0(Int fi) { /// - heapused /// Heap (data-base) space used, in bytes. /// - RINT(HeapUsed); + RINT(Yap_HeapUsed()); case op_localsp: /// - local /// Local stack in use, in bytes diff --git a/C/qlyr.c b/C/qlyr.c index dc25cba5c..9fd35c3e9 100755 --- a/C/qlyr.c +++ b/C/qlyr.c @@ -836,6 +836,7 @@ static void ReadHash(FILE *stream) { UInt sz = read_UInt(stream); UInt nrefs = read_UInt(stream); LogUpdClause *ncl = (LogUpdClause *)Yap_AlwaysAllocCodeSpace(sz); + Yap_LUClauseSpace += sz; if (!ncl) { QLYR_ERROR(OUT_OF_CODE_SPACE); } @@ -874,6 +875,7 @@ static void read_clauses(FILE *stream, PredEntry *pp, UInt nclauses, nrefs = cl->ClRefCount; } else { cl = (LogUpdClause *)Yap_AlwaysAllocCodeSpace(size); + Yap_LUClauseSpace += size; } read_bytes(stream, cl, size); cl->ClFlags &= ~InUseMask; @@ -887,6 +889,7 @@ static void read_clauses(FILE *stream, PredEntry *pp, UInt nclauses, char *base = (void *)read_UInt(stream); UInt mask = read_UInt(stream); UInt size = read_UInt(stream); + Yap_ClauseSpace += size; MegaClause *cl = (MegaClause *)Yap_AlwaysAllocCodeSpace(size); if (nclauses) { @@ -918,6 +921,7 @@ static void read_clauses(FILE *stream, PredEntry *pp, UInt nclauses, char *base = (void *)read_UInt(stream); UInt size = read_UInt(stream); DynamicClause *cl = (DynamicClause *)Yap_AlwaysAllocCodeSpace(size); + Yap_LUClauseSpace += size; LOCAL_HDiff = (char *)cl - base; read_bytes(stream, cl, size); @@ -948,6 +952,7 @@ static void read_clauses(FILE *stream, PredEntry *pp, UInt nclauses, char *base = (void *)read_UInt(stream); UInt size = read_UInt(stream); StaticClause *cl = (StaticClause *)Yap_AlwaysAllocCodeSpace(size); + Yap_ClauseSpace += size; LOCAL_HDiff = (char *)cl - base; read_bytes(stream, cl, size); diff --git a/H/alloc.h b/H/alloc.h index fdfe16776..8022e8240 100644 --- a/H/alloc.h +++ b/H/alloc.h @@ -96,10 +96,11 @@ typedef struct FREEB { /* Operating system and architecture dependent page size */ extern size_t Yap_page_size; -void Yap_InitHeap(void *); -UInt Yap_ExtendWorkSpaceThroughHole(UInt); -void Yap_AllocHole(UInt, UInt); - +extern void Yap_InitHeap(void *); +extern UInt Yap_ExtendWorkSpaceThroughHole(UInt); +extern void Yap_AllocHole(UInt, UInt); +extern size_t Yap_HeapUsed(void); +; #if USE_SYSTEM_MMAP && ! defined(__CYGWIN__) #include @@ -107,7 +108,7 @@ void Yap_AllocHole(UInt, UInt); #elif USE_SYSTEM_SHM - + #elif USE_SBRK @@ -120,10 +121,10 @@ void *sbrk(caddr_t); typedef unsigned size_t; -MALLOC_T malloc(size_t); -void free(MALLOC_T); -MALLOC_T realloc(MALLOC_T,size_t); -MALLOC_T calloc(size_t,size_t); +extern MALLOC_T malloc(size_t); +extern void free(MALLOC_T); +extern MALLOC_T realloc(MALLOC_T,size_t); +extern MALLOC_T calloc(size_t,size_t); #endif diff --git a/packages/python/pypreds.c b/packages/python/pypreds.c index 292e223e3..3f3179588 100644 --- a/packages/python/pypreds.c +++ b/packages/python/pypreds.c @@ -777,7 +777,7 @@ install_t install_pypreds(void) { PL_register_foreign("python_access", 3, python_access, 0); PL_register_foreign("python_threaded", 0, p_python_threaded, 0); PL_register_foreign("python_clear_errors", 0, python_clear_errors, 0); - PL_register_foreign("python_string_to", 0, python_string_to, 1); + PL_register_foreign("python_string_to", 1, python_string_to, 0); init_python_vfs(); }