Use Doug Lea's malloc as an alternative to YAP's standard malloc

don't use TR directly in scanner/parser, this avoids trouble with ^C while
consulting large files.
pass gcc -mno-cygwin to library compilation in cygwin environment (cygwin should
compile out of the box now).


git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1168 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
vsc
2004-10-28 20:12:23 +00:00
parent f267e74737
commit 2dfdca263d
19 changed files with 4503 additions and 83 deletions

View File

@@ -12,7 +12,7 @@
* Last rev: *
* mods: *
* comments: allocating space *
* version:$Id: alloc.c,v 1.62 2004-10-27 15:56:32 vsc Exp $ *
* version:$Id: alloc.c,v 1.63 2004-10-28 20:12:20 vsc Exp $ *
*************************************************************************/
#ifdef SCCS
static char SccsId[] = "%W% %G%";
@@ -30,6 +30,9 @@ static char SccsId[] = "%W% %G%";
#if HAVE_MALLOC_H
#include <malloc.h>
#endif
#if USE_DL_MALLOC
#include "dlmalloc.h"
#endif
#if HAVE_MEMORY_H
#include <memory.h>
#endif
@@ -54,7 +57,13 @@ static char SccsId[] = "%W% %G%";
/************************************************************************/
/* Yap workspace management */
#if USE_SYSTEM_MALLOC
#if USE_SYSTEM_MALLOC||USE_DL_MALLOC
#if USE_DL_MALLOC
#define malloc Yap_dlmalloc
#define free Yap_dlfree
#define realloc Yap_dlrealloc
#endif
char *
Yap_AllocCodeSpace(unsigned int size)
@@ -112,13 +121,24 @@ Yap_ExpandPreAllocCodeSpace(UInt sz0)
ScratchPad.sz =
sz = sz + sz0;
if (!(ptr = realloc(ScratchPad.ptr, sz)))
while (!(ptr = realloc(ScratchPad.ptr, sz))) {
#if USE_DL_MALLOC
if (!Yap_growheap(FALSE, sz, NULL)) {
return NULL;
}
#else
return NULL;
#endif
}
ScratchPad.ptr = ptr;
AuxSp = (CELL *)(AuxTop = ptr+sz);
return ptr;
}
#endif
#if USE_SYSTEM_MALLOC
struct various_codes *heap_regs;
static void
@@ -236,16 +256,18 @@ Yap_AllocHole(UInt actual_request, UInt total_size)
#define snprintf5(A,B,C,D,E) sprintf(A,C,D,E)
#endif
#ifdef LIGHT
#include <stdlib.h>
#endif
#if !USE_DL_MALLOC
STATIC_PROTO(void FreeBlock, (BlockHeader *));
STATIC_PROTO(BlockHeader *GetBlock, (unsigned int));
STATIC_PROTO(char *AllocHeap, (unsigned int));
STATIC_PROTO(void RemoveFromFreeList, (BlockHeader *));
STATIC_PROTO(void AddToFreeList, (BlockHeader *));
#ifdef LIGHT
#include <stdlib.h>
#endif
#define MinHGap 256*K
static void
@@ -494,6 +516,15 @@ FreeCodeSpace(char *p)
FreeBlock(((BlockHeader *) (p - sizeof(YAP_SEG_SIZE))));
}
static char *
AllocCodeSpace(unsigned int size)
{
if (size < SmallSize + 2 * OpCodeSize + 3 * CellSize)
return (AllocHeap(SmallSize + 2 * OpCodeSize + 3 * CellSize));
return (AllocHeap(size));
}
#if DEBUG_ALLOC
int vsc_mem_trace;
#endif
@@ -530,14 +561,6 @@ Yap_FreeAtomSpace(char *p)
FreeCodeSpace(p);
}
static char *
AllocCodeSpace(unsigned int size)
{
if (size < SmallSize + 2 * OpCodeSize + 3 * CellSize)
return (AllocHeap(SmallSize + 2 * OpCodeSize + 3 * CellSize));
return (AllocHeap(size));
}
char *
Yap_AllocCodeSpace(unsigned int size)
{
@@ -557,6 +580,7 @@ Yap_ExpandPreAllocCodeSpace(UInt sz)
}
return Addr(HeapTop) + sizeof(CELL);
}
#endif
/************************************************************************/
@@ -1229,13 +1253,15 @@ 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));
#if USE_DL_MALLOC
Yap_initdlmalloc();
#else
HeapMax = HeapUsed = HeapTop-Yap_HeapBase;
/* notice that this forces odd addresses */
*((YAP_SEG_SIZE *) HeapTop) = InUseFlag;
HeapTop = HeapTop + sizeof(YAP_SEG_SIZE);
*((YAP_SEG_SIZE *) HeapTop) = InUseFlag;
#endif
FreeBlocks = NIL;
@@ -1302,7 +1328,9 @@ Yap_InitMemory(int Trail, int Heap, int Stack)
HeapLim = Yap_GlobalBase; /* avoid confusions while
* * restoring */
#if !USE_DL_MALLOC
AuxTop = (ADDR)(AuxSp = (CELL *)Yap_GlobalBase);
#endif
#ifdef DEBUG
#if SIZEOF_INT_P!=SIZEOF_INT
@@ -1330,6 +1358,11 @@ Yap_InitMemory(int Trail, int Heap, int Stack)
void
Yap_InitExStacks(int Trail, int Stack)
{
#if USE_DL_MALLOC
ScratchPad.ptr = NULL;
ScratchPad.sz = ScratchPad.msz = SCRATCH_START_SIZE;
AuxSp = NULL;
#endif
}
#if defined(_WIN32)
@@ -1359,6 +1392,10 @@ Yap_ExtendWorkSpaceThroughHole(UInt s)
/* progress 1 MB */
WorkSpaceTop += 512*1024;
if (ExtendWorkSpace(s, MAP_FIXED)) {
#if USE_DL_MALLOC
Yap_hole_start = (ADDR)WorkSpaceTop0;
Yap_hole_end = (ADDR)WorkSpaceTop-s;
#endif
return WorkSpaceTop-WorkSpaceTop0;
}
#if defined(_WIN32)
@@ -1381,7 +1418,7 @@ Yap_ExtendWorkSpaceThroughHole(UInt s)
void
Yap_AllocHole(UInt actual_request, UInt total_size)
{
#if USE_MMAP || defined(_WIN32)
#if (USE_MMAP || defined(_WIN32)) && !USE_DL_MALLOC
/* where we were when the hole was created,
also where is the hole store */
ADDR WorkSpaceTop0 = WorkSpaceTop-total_size;

View File

@@ -10,8 +10,13 @@
* File: c_interface.c *
* comments: c_interface primitives definition *
* *
* Last rev: $Date: 2004-10-06 16:55:46 $,$Author: vsc $ *
* Last rev: $Date: 2004-10-28 20:12:20 $,$Author: vsc $ *
* $Log: not supported by cvs2svn $
* Revision 1.54 2004/10/06 16:55:46 vsc
* change configure to support big mem configs
* get rid of extra globals
* fix trouble with multifile preds
*
* Revision 1.53 2004/08/11 16:14:51 vsc
* whole lot of fixes:
* - memory leak in indexing
@@ -912,14 +917,12 @@ X_API Term
YAP_Read(int (*mygetc)(void))
{
Term t;
tr_fr_ptr old_TR;
int sno;
TokEntry *tokstart;
BACKUP_MACHINE_REGS();
do_getf = mygetc;
old_TR = TR;
sno = Yap_GetFreeStreamD();
if (sno < 0) {
Yap_Error(SYSTEM_ERROR,TermNil, "new stream not available for YAP_Read");
@@ -930,13 +933,11 @@ YAP_Read(int (*mygetc)(void))
Stream[sno].status = Free_Stream_f;
if (Yap_ErrorMessage)
{
TR = old_TR;
save_machine_regs();
return(0);
}
t = Yap_Parse();
Yap_clean_tokenizer(tokstart, Yap_VarTable, Yap_AnonVarTable);
TR = old_TR;
RECOVER_MACHINE_REGS();
return t;

View File

@@ -11,8 +11,11 @@
* File: cdmgr.c *
* comments: Code manager *
* *
* Last rev: $Date: 2004-10-26 20:15:51 $,$Author: vsc $ *
* Last rev: $Date: 2004-10-28 20:12:21 $,$Author: vsc $ *
* $Log: not supported by cvs2svn $
* Revision 1.138 2004/10/26 20:15:51 vsc
* More bug fixes for overflow handling
*
* Revision 1.137 2004/10/22 16:53:19 vsc
* bug fixes
*
@@ -2716,7 +2719,7 @@ search_for_static_predicate_in_use(PredEntry *p, int check_everything)
if (b_ptr)
pe = PredForChoicePt(b_ptr->cp_ap);
else
return NULL;
return FALSE;
if (pe == p) {
if (check_everything)
return TRUE;
@@ -2789,7 +2792,7 @@ do_toggle_static_predicates_in_use(int mask)
}
/* now mark the choicepoint */
if ((b_ptr)) {
if (pe = PredForChoicePt(b_ptr->cp_ap)) {
if ((pe = PredForChoicePt(b_ptr->cp_ap))) {
mark_pred(mask, pe);
}
}

3176
C/dlmalloc.c Executable file

File diff suppressed because it is too large Load Diff

View File

@@ -120,7 +120,7 @@ SetHeapRegs(void)
Yap_TrailTop = TrailAddrAdjust(Yap_TrailTop);
Yap_GlobalBase = DelayAddrAdjust(Yap_GlobalBase);
Yap_LocalBase = LocalAddrAdjust(Yap_LocalBase);
#if !USE_SYSTEM_MALLOC
#if !USE_SYSTEM_MALLOC && !USE_DL_MALLOC
AuxSp = PtoDelayAdjust(AuxSp);
AuxTop = (ADDR)PtoDelayAdjust((CELL *)AuxTop);
#endif
@@ -1272,7 +1272,7 @@ Yap_growtrail(long size)
CELL **
Yap_shift_visit(CELL **to_visit, CELL ***to_visit_maxp)
{
#if USE_SYSTEM_MALLOC
#if USE_SYSTEM_MALLOC || USE_DL_MALLOC
CELL **to_visit_max = *to_visit_maxp;
Int sz1 = (CELL)to_visit_max-(CELL)to_visit;
Int sz0 = AuxTop - (ADDR)to_visit_maxp, sz, dsz;

View File

@@ -94,7 +94,7 @@ static cont *cont_top0;
#endif
static cont *cont_top;
static int
static void
gc_growtrail(int committed)
{
#if USE_SYSTEM_MALLOC
@@ -112,6 +112,7 @@ gc_growtrail(int committed)
#endif
longjmp(Yap_gc_restore, 1);
#endif
}
inline static void

View File

@@ -2957,13 +2957,11 @@ do_read(int inp_stream)
#if EMACS
int emacs_cares = FALSE;
#endif
tr_fr_ptr old_TR, TR_before_parse;
if (Stream[inp_stream].status & Binary_Stream_f) {
Yap_Error(PERMISSION_ERROR_INPUT_BINARY_STREAM, MkAtomTerm(Stream[inp_stream].u.file.name), "read_term/2");
return(FALSE);
}
old_TR = TR;
while (TRUE) {
CELL *old_H;
@@ -2981,7 +2979,6 @@ do_read(int inp_stream)
if (tokstart != NIL && tokstart->Tok != Ord (eot_tok)) {
/* we got the end of file from an abort */
if (Yap_ErrorMessage == "Abort") {
TR = old_TR;
Yap_clean_tokenizer(tokstart, Yap_VarTable, Yap_AnonVarTable);
return FALSE;
}
@@ -2989,8 +2986,6 @@ do_read(int inp_stream)
Stream[inp_stream].status |= Push_Eof_Stream_f;
Yap_ErrorMessage = "end of file found before end of term";
} else {
/* restore TR */
TR = old_TR;
Yap_clean_tokenizer(tokstart, Yap_VarTable, Yap_AnonVarTable);
return (Yap_unify(MkIntegerTerm(StartLine = Stream[inp_stream].linecount),ARG4) &&
@@ -2999,27 +2994,29 @@ do_read(int inp_stream)
}
}
repeat_cycle:
TR_before_parse = TR;
if (Yap_ErrorMessage || (t = Yap_Parse ()) == 0) {
if (Yap_ErrorMessage || (t = Yap_Parse()) == 0) {
if (Yap_ErrorMessage && (strcmp(Yap_ErrorMessage,"Stack Overflow") == 0)) {
/* ignore term we just built */
TR = TR_before_parse;
H = old_H;
tr_fr_ptr old_TR = TR;
TR = (tr_fr_ptr)ScannerStack;
if (Yap_growstack_in_parser(&old_TR, &tokstart, &Yap_VarTable)) {
ScannerStack = (char *)TR;
TR = old_TR;
old_H = H;
Yap_tokptr = Yap_toktide = tokstart;
Yap_ErrorMessage = NULL;
goto repeat_cycle;
}
ScannerStack = (char *)TR;
TR = old_TR;
}
TR = old_TR;
if (ParserErrorStyle == QUIET_ON_PARSER_ERROR) {
/* just fail */
Yap_clean_tokenizer(tokstart, Yap_VarTable, Yap_AnonVarTable);
return FALSE;
} else if (ParserErrorStyle == CONTINUE_ON_PARSER_ERROR) {
Yap_ErrorMessage = NULL;
TR = TR_before_parse;
/* try again */
goto repeat_cycle;
} else {
@@ -3055,14 +3052,17 @@ do_read(int inp_stream)
if (setjmp(Yap_IOBotch) == 0) {
v = Yap_VarNames(Yap_VarTable, TermNil);
TR = old_TR;
break;
} else {
tr_fr_ptr old_TR = TR;
/* don't need to recheck tokens */
tokstart = NULL;
/* restart global */
H = old_H;
TR = (tr_fr_ptr)ScannerStack;
Yap_growstack_in_parser(&old_TR, &tokstart, &Yap_VarTable);
ScannerStack = (char *)TR;
TR = old_TR;
old_H = H;
}
}
@@ -3070,7 +3070,6 @@ do_read(int inp_stream)
return(Yap_unify(t, ARG2) && Yap_unify (v, ARG3) &&
Yap_unify(MkIntTerm(StartLine = tokstart->TokPos),ARG4));
} else {
TR = old_TR;
Yap_clean_tokenizer(tokstart, Yap_VarTable, Yap_AnonVarTable);
return(Yap_unify(t, ARG2) && Yap_unify(MkIntTerm(StartLine = tokstart->TokPos),ARG4));
}

View File

@@ -306,8 +306,12 @@ ParseArgs(Atom a, JMPBUFF *FailBuff)
p = (Term *) ParserAuxSp;
while (1) {
Term *tp = (Term *)ParserAuxSp;
if (ParserAuxSp+1 > Yap_TrailTop) {
Yap_ErrorMessage = "Trail Overflow";
FAIL;
}
*tp++ = Unsigned(ParseTerm(999, FailBuff));
ParserAuxSp = (tr_fr_ptr)tp;
ParserAuxSp = tp;
++nargs;
if (Yap_tokptr->Tok != Ord(Ponctuation_tok))
break;
@@ -315,7 +319,7 @@ ParseArgs(Atom a, JMPBUFF *FailBuff)
break;
NextToken;
}
ParserAuxSp = (tr_fr_ptr)p;
ParserAuxSp = (char *)p;
/*
* Needed because the arguments for the functor are placed in reverse
* order

View File

@@ -402,6 +402,8 @@ save_regs(int mode)
putout(Unsigned(HeapUsed));
/* Then the start of the free code */
putcellptr(CellPtr(FreeBlocks));
putcellptr(AuxSp);
putcellptr(CellPtr(AuxTop));
if (mode == DO_EVERYTHING) {
/* put the old trail base, just in case it moves again */
putout(ARG1);
@@ -680,6 +682,8 @@ get_heap_info(void)
OldHeapTop = (ADDR) get_cellptr();
OldHeapUsed = (Int) get_cell();
FreeBlocks = (BlockHeader *) get_cellptr();
AuxSp = get_cellptr();
AuxTop = (ADDR)get_cellptr();
HDiff = Unsigned(Yap_HeapBase) - Unsigned(OldHeapBase);
}
@@ -1065,6 +1069,10 @@ RestoreFreeSpace(void)
if (FreeBlocks != NULL)
FreeBlocks = BlockAdjust(FreeBlocks);
bpt = FreeBlocks;
if (AuxSp != NULL)
AuxSp = CellPtoHeapAdjust(AuxSp);
if (AuxTop != NULL)
AuxTop = AddrAdjust(AuxTop);
while (bpt != NULL) {
if (bpt->b_next != NULL) {
bsz = bpt->b_next = BlockAdjust(bpt->b_next);

View File

@@ -130,23 +130,22 @@ AllocScannerMemory(unsigned int size)
#else
char *AuxSpScan;
AuxSpScan = (char *)TR;
AuxSpScan = ScannerStack;
size = AdjustSize(size);
TR = (tr_fr_ptr)(AuxSpScan+size);
#if !OS_HANDLES_TR_OVERFLOW
if (Unsigned(Yap_TrailTop) == Unsigned(TR)) {
ScannerStack = AuxSpScan+size;
if (Yap_TrailTop <= ScannerStack) {
if(!Yap_growtrail (sizeof(CELL) * 16 * 1024L)) {
return(NULL);
}
}
#endif
return (AuxSpScan);
return AuxSpScan;
#endif
}
char *
Yap_AllocScannerMemory(unsigned int size)
{
/* I assume memory has been initialised */
return AllocScannerMemory(size);
}
@@ -380,7 +379,7 @@ read_quoted_char(int *scan_nextp, int inp_stream, int (*QuotedNxtch)(int))
static Term
get_num(int *chp, int *chbuffp, int inp_stream, int (*Nxtch) (int), int (*QuotedNxtch) (int))
{
char *s = (char *)TR, *sp = s;
char *s = (char *)ScannerStack, *sp = s;
int ch = *chp;
Int val = 0, base = ch - '0';
int might_be_float = TRUE, has_overflow = FALSE;
@@ -549,6 +548,7 @@ Yap_scan_num(int (*Nxtch) (int))
int ch, cherr;
Yap_ErrorMessage = NULL;
ScannerStack = (char *)TR;
ch = Nxtch(-1);
if (ch == '-') {
sign = -1;
@@ -586,6 +586,7 @@ Yap_tokenizer(int inp_stream)
Yap_VarTable = NULL;
Yap_AnonVarTable = NULL;
Yap_eot_before_eof = FALSE;
ScannerStack = (char *)TR;
l = NIL;
p = NIL; /* Just to make lint happy */
ch = Nxtch(inp_stream);