fixes for stack overflow
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@982 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
parent
6662ca157e
commit
f1063a27b2
@ -2634,7 +2634,10 @@ PredForCode(yamop *codeptr, Atom *pat, UInt *parity, Term *pmodule) {
|
||||
PredEntry *pp = ModulePred[i_table];
|
||||
while (pp != NULL) {
|
||||
if ((found = code_in_pred(pp, pat, parity, codeptr)) != 0) {
|
||||
*pmodule = i_table;
|
||||
if (i_table)
|
||||
*pmodule = ModuleName[i_table];
|
||||
else
|
||||
*pmodule = TermProlog;
|
||||
return(found);
|
||||
}
|
||||
pp = pp->NextPredOfModule;
|
||||
|
19
C/dbase.c
19
C/dbase.c
@ -2450,6 +2450,7 @@ GetDBTerm(DBTerm *DBSP)
|
||||
fprintf(Yap_stderr, "\n\n [ FATAL ERROR: No Stack for Error Handling ]\n");
|
||||
Yap_exit( 1);
|
||||
} else {
|
||||
Yap_Error_Size = NOf*sizeof(CELL);
|
||||
return((Term)0);
|
||||
}
|
||||
}
|
||||
@ -3057,7 +3058,7 @@ i_recorded(DBProp AtProp, Term t3)
|
||||
/* make sure the garbage collector sees what we want it to see! */
|
||||
EXTRA_CBACK_ARG(3,1) = (CELL)ref;
|
||||
/* oops, we are in trouble, not enough stack space */
|
||||
if (!Yap_gc(3, ENV, CP)) {
|
||||
if (!Yap_gcl(Yap_Error_Size, 3, ENV, CP)) {
|
||||
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
|
||||
return(FALSE);
|
||||
}
|
||||
@ -3119,7 +3120,7 @@ i_recorded(DBProp AtProp, Term t3)
|
||||
EXTRA_CBACK_ARG(3,2) = MkIntegerTerm(((Int)mask));
|
||||
EXTRA_CBACK_ARG(3,3) = MkIntegerTerm(((Int)key));
|
||||
/* oops, we are in trouble, not enough stack space */
|
||||
if (!Yap_gc(3, ENV, CP)) {
|
||||
if (!Yap_gcl(Yap_Error_Size, 3, ENV, CP)) {
|
||||
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
|
||||
return(FALSE);
|
||||
}
|
||||
@ -3206,7 +3207,7 @@ c_recorded(int flags)
|
||||
/* make sure the garbage collector sees what we want it to see! */
|
||||
EXTRA_CBACK_ARG(3,1) = (CELL)ref;
|
||||
/* oops, we are in trouble, not enough stack space */
|
||||
if (!Yap_gc(3, ENV, CP)) {
|
||||
if (!Yap_gcl(Yap_Error_Size, 3, ENV, CP)) {
|
||||
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
|
||||
return(FALSE);
|
||||
}
|
||||
@ -3239,7 +3240,7 @@ c_recorded(int flags)
|
||||
/* make sure the garbage collector sees what we want it to see! */
|
||||
EXTRA_CBACK_ARG(3,1) = (CELL)ref;
|
||||
/* oops, we are in trouble, not enough stack space */
|
||||
if (!Yap_gc(3, ENV, CP)) {
|
||||
if (!Yap_gcl(Yap_Error_Size, 3, ENV, CP)) {
|
||||
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
|
||||
return(FALSE);
|
||||
}
|
||||
@ -3475,7 +3476,7 @@ p_first_instance(void)
|
||||
#endif
|
||||
while ((TermDB = GetDBTermFromDBEntry(ref)) == (CELL)0) {
|
||||
/* oops, we are in trouble, not enough stack space */
|
||||
if (!Yap_gc(3, ENV, P)) {
|
||||
if (!Yap_gcl(Yap_Error_Size, 3, ENV, P)) {
|
||||
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
|
||||
return(FALSE);
|
||||
}
|
||||
@ -4328,7 +4329,7 @@ static_instance(StaticClause *cl)
|
||||
|
||||
while ((TermDB = GetDBTerm(cl->usc.ClSource)) == 0L) {
|
||||
/* oops, we are in trouble, not enough stack space */
|
||||
if (!Yap_gc(2, ENV, P)) {
|
||||
if (!Yap_gcl(Yap_Error_Size, 2, ENV, P)) {
|
||||
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
|
||||
return(FALSE);
|
||||
}
|
||||
@ -4398,7 +4399,7 @@ p_instance(void)
|
||||
Term TermDB;
|
||||
while ((TermDB = GetDBTerm(cl->ClSource)) == 0L) {
|
||||
/* oops, we are in trouble, not enough stack space */
|
||||
if (!Yap_gc(2, ENV, P)) {
|
||||
if (!Yap_gcl(Yap_Error_Size, 2, ENV, P)) {
|
||||
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
|
||||
return(FALSE);
|
||||
}
|
||||
@ -4409,7 +4410,7 @@ p_instance(void)
|
||||
Term TermDB;
|
||||
while ((TermDB = GetDBTermFromDBEntry(dbr)) == 0L) {
|
||||
/* oops, we are in trouble, not enough stack space */
|
||||
if (!Yap_gc(2, ENV, P)) {
|
||||
if (!Yap_gcl(Yap_Error_Size, 2, ENV, P)) {
|
||||
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
|
||||
return(FALSE);
|
||||
}
|
||||
@ -4810,7 +4811,7 @@ p_dequeue(void)
|
||||
father_key->FirstInQueue = cur_instance->next;
|
||||
WRITE_UNLOCK(father_key->QRWLock);
|
||||
while ((TDB = GetDBTerm(cur_instance->DBT)) == 0L) {
|
||||
if (!Yap_gc(2, YENV, P)) {
|
||||
if (!Yap_gcl(Yap_Error_Size, 2, YENV, P)) {
|
||||
Yap_Error(OUT_OF_STACK_ERROR, TermNil, Yap_ErrorMessage);
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -3156,7 +3156,7 @@ do_gc(Int predarity, CELL *current_env, yamop *nextop)
|
||||
(unsigned long int)(ASP-H));
|
||||
}
|
||||
check_global();
|
||||
return(effectiveness);
|
||||
return effectiveness;
|
||||
}
|
||||
|
||||
static int
|
||||
@ -3229,7 +3229,6 @@ call_gc(UInt gc_lim, Int predarity, CELL *current_env, yamop *nextop)
|
||||
gc_margin <<= 8;
|
||||
gc_margin *= gc_calls;
|
||||
}
|
||||
gc_margin *= Yap_page_size;
|
||||
}
|
||||
if (gc_margin < gc_lim)
|
||||
gc_margin = gc_lim;
|
||||
@ -3244,7 +3243,7 @@ call_gc(UInt gc_lim, Int predarity, CELL *current_env, yamop *nextop)
|
||||
effectiveness = 0;
|
||||
}
|
||||
/* expand the stack if effectiveness is less than 20 % */
|
||||
if (ASP - H < gc_margin ||
|
||||
if (ASP - H < gc_margin/sizeof(CELL) ||
|
||||
effectiveness < 20) {
|
||||
return (Yap_growstack(gc_margin));
|
||||
}
|
||||
@ -3258,13 +3257,13 @@ call_gc(UInt gc_lim, Int predarity, CELL *current_env, yamop *nextop)
|
||||
int
|
||||
Yap_gc(Int predarity, CELL *current_env, yamop *nextop)
|
||||
{
|
||||
return call_gc(128, predarity, current_env, nextop);
|
||||
return call_gc(4096, predarity, current_env, nextop);
|
||||
}
|
||||
|
||||
int
|
||||
Yap_gcl(UInt gc_lim, Int predarity, CELL *current_env, yamop *nextop)
|
||||
{
|
||||
return call_gc(gc_lim, predarity, current_env, nextop);
|
||||
return call_gc(gc_lim+CalculateStackGap()*sizeof(CELL), predarity, current_env, nextop);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1771,7 +1771,7 @@ init_current_predicate(void)
|
||||
Term t1 = Deref(ARG1);
|
||||
|
||||
if (IsVarTerm(t1) || !IsAtomTerm(t1)) cut_fail();
|
||||
EXTRA_CBACK_ARG(3,1) = t1;
|
||||
EXTRA_CBACK_ARG(3,1) = MkIntegerTerm((Int)Yap_ModulePred(t1));
|
||||
return (cont_current_predicate());
|
||||
}
|
||||
|
||||
|
@ -2275,7 +2275,7 @@ int WINAPI win_yap(HANDLE hinst, DWORD reason, LPVOID reserved)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
#if (defined(YAPOR) || defined(THREADS)) && !defined(USE_PTHREAD_LOCKING)
|
||||
#ifdef sparc
|
||||
void STD_PROTO(rw_lock_voodoo,(void));
|
||||
|
||||
|
@ -115,6 +115,10 @@ low_level_trace(yap_low_level_port port, PredEntry *pred, CELL *args)
|
||||
/* extern int gc_calls; */
|
||||
|
||||
vsc_count++;
|
||||
if (vsc_count < 59966299LL)
|
||||
return;
|
||||
if (vsc_count == 59966301LL)
|
||||
vsc_xstop=1;
|
||||
#ifdef COMMENTED
|
||||
if (port != enter_pred ||
|
||||
!pred ||
|
||||
|
@ -1168,16 +1168,9 @@ IUnify_complex(CELL *pt0, CELL *pt0_end, CELL *pt1)
|
||||
register CELL *HBREG = HB;
|
||||
#endif /* SHADOW_HB */
|
||||
|
||||
#if USE_SYSTEM_MALLOC
|
||||
CELL **to_visit_max = (CELL **)Yap_PreAllocCodeSpace(), **to_visit = (CELL **)AuxSp;
|
||||
#define address_to_visit_max (&to_visit_max)
|
||||
#define to_visit_base ((CELL **)AuxSp)
|
||||
#else
|
||||
CELL **to_visit = (CELL **)Yap_TrailTop;
|
||||
#define to_visit_max ((CELL **)TR)
|
||||
#define address_to_visit_max NULL
|
||||
#define to_visit_base ((CELL **)Yap_TrailTop)
|
||||
#endif
|
||||
|
||||
loop:
|
||||
while (pt0 < pt0_end) {
|
||||
|
11
H/rheap.h
11
H/rheap.h
@ -730,14 +730,18 @@ restore_opcodes(yamop *pc)
|
||||
break;
|
||||
/* instructions type sla */
|
||||
case _p_execute:
|
||||
goto sla_full;
|
||||
pc->u.sla.sla_u.p = PtoPredAdjust(pc->u.sla.sla_u.p);
|
||||
if (pc->u.sla.sla_u.mod != 0) {
|
||||
pc->u.sla.sla_u.mod = AtomTermAdjust(pc->u.sla.sla_u.mod);
|
||||
}
|
||||
pc->u.sla.p0 = PtoPredAdjust(pc->u.sla.p0);
|
||||
pc = NEXTOP(pc,sla);
|
||||
case _fcall:
|
||||
case _call:
|
||||
#ifdef YAPOR
|
||||
case _or_last:
|
||||
#endif
|
||||
pc->u.sla.sla_u.p = PtoPredAdjust(pc->u.sla.sla_u.p);
|
||||
sla_full:
|
||||
if (pc->u.sla.bmap != NULL) {
|
||||
pc->u.sla.bmap = CellPtoHeapAdjust(pc->u.sla.bmap);
|
||||
}
|
||||
@ -1521,6 +1525,9 @@ CleanCode(PredEntry *pp)
|
||||
pp->FunctorOfPred = FuncAdjust(pp->FunctorOfPred);
|
||||
else
|
||||
pp->FunctorOfPred = (Functor)AtomAdjust((Atom)(pp->FunctorOfPred));
|
||||
if (pp->ModuleOfPred) {
|
||||
pp->ModuleOfPred = AtomTermAdjust(pp->ModuleOfPred);
|
||||
}
|
||||
if (pp->ModuleOfPred != IDB_MODULE) {
|
||||
if (pp->src.OwnerFile && pp->ModuleOfPred != IDB_MODULE)
|
||||
pp->src.OwnerFile = AtomAdjust(pp->src.OwnerFile);
|
||||
|
@ -119,7 +119,8 @@ HEADERS = \
|
||||
$(srcdir)/OPTYap/tab.structs.h $(srcdir)/OPTYap/x86_locks.h \
|
||||
$(srcdir)/OPTYap/sparc_locks.h $(srcdir)/OPTYap/mips_locks.h \
|
||||
$(srcdir)/OPTYap/mips_locks_funcs.h $(srcdir)/OPTYap/alpha_locks.h \
|
||||
$(srcdir)/OPTYap/alpha_locks_funcs.h
|
||||
$(srcdir)/OPTYap/alpha_locks_funcs.h \
|
||||
$(srcdir)/OPTYap/pthread_locks.h
|
||||
|
||||
C_SOURCES= \
|
||||
$(srcdir)/C/absmi.c $(srcdir)/C/adtdefs.c \
|
||||
|
57
configure
vendored
57
configure
vendored
@ -853,6 +853,7 @@ Optional Features:
|
||||
--enable-low-level-tracer support support for procedure-call tracing
|
||||
--enable-tabling support tabling as: batched,local
|
||||
--enable-threads support system threads
|
||||
--pthread-locking use pthread locking primitives for internal locking (requires threads)
|
||||
--enable-max-performance try using the best flags for specific architecture
|
||||
--enable-debug-yap enable C-debugging for YAP
|
||||
--enable-cygwin use cygwin library in WIN32
|
||||
@ -2307,6 +2308,13 @@ if test "${enable_threads+set}" = set; then
|
||||
else
|
||||
threads=no
|
||||
fi;
|
||||
# Check whether --enable-pthread-locking or --disable-pthread-locking was given.
|
||||
if test "${enable_pthread_locking+set}" = set; then
|
||||
enableval="$enable_pthread_locking"
|
||||
pthreadlocking="$enableval"
|
||||
else
|
||||
pthreadlocking=no
|
||||
fi;
|
||||
# Check whether --enable-max-performance or --disable-max-performance was given.
|
||||
if test "${enable_max_performance+set}" = set; then
|
||||
enableval="$enable_max_performance"
|
||||
@ -4773,6 +4781,13 @@ _ACEOF
|
||||
fi
|
||||
done
|
||||
|
||||
if test "$pthreadlocking" = yes
|
||||
then
|
||||
cat >>confdefs.h <<\_ACEOF
|
||||
#define USE_PTHREAD_LOCKING 1
|
||||
_ACEOF
|
||||
|
||||
fi
|
||||
fi
|
||||
|
||||
MPI_OBJS=
|
||||
@ -9404,10 +9419,8 @@ See \`config.log' for more details." >&2;}
|
||||
esac
|
||||
else
|
||||
if test "$cross_compiling" = yes; then
|
||||
{ { echo "$as_me:$LINENO: error: cannot run test program while cross compiling
|
||||
See \`config.log' for more details." >&5
|
||||
echo "$as_me: error: cannot run test program while cross compiling
|
||||
See \`config.log' for more details." >&2;}
|
||||
{ { echo "$as_me:$LINENO: error: internal error: not reached in cross-compile" >&5
|
||||
echo "$as_me: error: internal error: not reached in cross-compile" >&2;}
|
||||
{ (exit 1); exit 1; }; }
|
||||
else
|
||||
cat >conftest.$ac_ext <<_ACEOF
|
||||
@ -9812,10 +9825,8 @@ See \`config.log' for more details." >&2;}
|
||||
esac
|
||||
else
|
||||
if test "$cross_compiling" = yes; then
|
||||
{ { echo "$as_me:$LINENO: error: cannot run test program while cross compiling
|
||||
See \`config.log' for more details." >&5
|
||||
echo "$as_me: error: cannot run test program while cross compiling
|
||||
See \`config.log' for more details." >&2;}
|
||||
{ { echo "$as_me:$LINENO: error: internal error: not reached in cross-compile" >&5
|
||||
echo "$as_me: error: internal error: not reached in cross-compile" >&2;}
|
||||
{ (exit 1); exit 1; }; }
|
||||
else
|
||||
cat >conftest.$ac_ext <<_ACEOF
|
||||
@ -10220,10 +10231,8 @@ See \`config.log' for more details." >&2;}
|
||||
esac
|
||||
else
|
||||
if test "$cross_compiling" = yes; then
|
||||
{ { echo "$as_me:$LINENO: error: cannot run test program while cross compiling
|
||||
See \`config.log' for more details." >&5
|
||||
echo "$as_me: error: cannot run test program while cross compiling
|
||||
See \`config.log' for more details." >&2;}
|
||||
{ { echo "$as_me:$LINENO: error: internal error: not reached in cross-compile" >&5
|
||||
echo "$as_me: error: internal error: not reached in cross-compile" >&2;}
|
||||
{ (exit 1); exit 1; }; }
|
||||
else
|
||||
cat >conftest.$ac_ext <<_ACEOF
|
||||
@ -10628,10 +10637,8 @@ See \`config.log' for more details." >&2;}
|
||||
esac
|
||||
else
|
||||
if test "$cross_compiling" = yes; then
|
||||
{ { echo "$as_me:$LINENO: error: cannot run test program while cross compiling
|
||||
See \`config.log' for more details." >&5
|
||||
echo "$as_me: error: cannot run test program while cross compiling
|
||||
See \`config.log' for more details." >&2;}
|
||||
{ { echo "$as_me:$LINENO: error: internal error: not reached in cross-compile" >&5
|
||||
echo "$as_me: error: internal error: not reached in cross-compile" >&2;}
|
||||
{ (exit 1); exit 1; }; }
|
||||
else
|
||||
cat >conftest.$ac_ext <<_ACEOF
|
||||
@ -11036,10 +11043,8 @@ See \`config.log' for more details." >&2;}
|
||||
esac
|
||||
else
|
||||
if test "$cross_compiling" = yes; then
|
||||
{ { echo "$as_me:$LINENO: error: cannot run test program while cross compiling
|
||||
See \`config.log' for more details." >&5
|
||||
echo "$as_me: error: cannot run test program while cross compiling
|
||||
See \`config.log' for more details." >&2;}
|
||||
{ { echo "$as_me:$LINENO: error: internal error: not reached in cross-compile" >&5
|
||||
echo "$as_me: error: internal error: not reached in cross-compile" >&2;}
|
||||
{ (exit 1); exit 1; }; }
|
||||
else
|
||||
cat >conftest.$ac_ext <<_ACEOF
|
||||
@ -11444,10 +11449,8 @@ See \`config.log' for more details." >&2;}
|
||||
esac
|
||||
else
|
||||
if test "$cross_compiling" = yes; then
|
||||
{ { echo "$as_me:$LINENO: error: cannot run test program while cross compiling
|
||||
See \`config.log' for more details." >&5
|
||||
echo "$as_me: error: cannot run test program while cross compiling
|
||||
See \`config.log' for more details." >&2;}
|
||||
{ { echo "$as_me:$LINENO: error: internal error: not reached in cross-compile" >&5
|
||||
echo "$as_me: error: internal error: not reached in cross-compile" >&2;}
|
||||
{ (exit 1); exit 1; }; }
|
||||
else
|
||||
cat >conftest.$ac_ext <<_ACEOF
|
||||
@ -11852,10 +11855,8 @@ See \`config.log' for more details." >&2;}
|
||||
esac
|
||||
else
|
||||
if test "$cross_compiling" = yes; then
|
||||
{ { echo "$as_me:$LINENO: error: cannot run test program while cross compiling
|
||||
See \`config.log' for more details." >&5
|
||||
echo "$as_me: error: cannot run test program while cross compiling
|
||||
See \`config.log' for more details." >&2;}
|
||||
{ { echo "$as_me:$LINENO: error: internal error: not reached in cross-compile" >&5
|
||||
echo "$as_me: error: internal error: not reached in cross-compile" >&2;}
|
||||
{ (exit 1); exit 1; }; }
|
||||
else
|
||||
cat >conftest.$ac_ext <<_ACEOF
|
||||
|
11
configure.in
11
configure.in
@ -39,6 +39,9 @@ AC_ARG_ENABLE(tabling,
|
||||
AC_ARG_ENABLE(threads,
|
||||
[ --enable-threads support system threads ],
|
||||
threads="$enableval", threads=no)
|
||||
AC_ARG_ENABLE(pthread-locking,
|
||||
[ --pthread-locking use pthread locking primitives for internal locking (requires threads) ],
|
||||
pthreadlocking="$enableval", pthreadlocking=no)
|
||||
AC_ARG_ENABLE(max-performance,
|
||||
[ --enable-max-performance try using the best flags for specific architecture ],
|
||||
maxperformance="$enableval", maxperformance=no)
|
||||
@ -339,6 +342,10 @@ then
|
||||
AC_CHECK_LIB(pthread,pthread_create)
|
||||
AC_CHECK_HEADERS(pthread.h)
|
||||
AC_CHECK_FUNCS(pthread_mutexattr_setkind_np pthread_mutexattr_settype)
|
||||
if test "$pthreadlocking" = yes
|
||||
then
|
||||
AC_DEFINE(USE_PTHREAD_LOCKING, 1)
|
||||
fi
|
||||
fi
|
||||
|
||||
MPI_OBJS=
|
||||
@ -658,6 +665,10 @@ fi
|
||||
if test "$threads" = "yes"
|
||||
then
|
||||
YAP_EXTRAS="$YAP_EXTRAS -DTHREADS=1"
|
||||
if test "$GCC" = "yes"
|
||||
then
|
||||
YAP_EXTRAS="$YAP_EXTRAS -D_GNU_SOURCE"
|
||||
fi
|
||||
fi
|
||||
|
||||
case "$orparallelism" in
|
||||
|
26
m4/Yap.h.m4
26
m4/Yap.h.m4
@ -10,7 +10,7 @@
|
||||
* File: Yap.h.m4 *
|
||||
* mods: *
|
||||
* comments: main header file for YAP *
|
||||
* version: $Id: Yap.h.m4,v 1.51 2004-02-05 16:57:01 vsc Exp $ *
|
||||
* version: $Id: Yap.h.m4,v 1.52 2004-02-12 17:09:17 vsc Exp $ *
|
||||
*************************************************************************/
|
||||
|
||||
#include "config.h"
|
||||
@ -332,20 +332,26 @@ typedef CELL Term;
|
||||
|
||||
#if !defined(YAPOR) && !defined(THREADS)
|
||||
#include <nolocks.h>
|
||||
#else
|
||||
#elif USE_PTHREAD_LOCKING
|
||||
typedef pthread_mutex_t lockvar;
|
||||
typedef pthread_rwlock_t rwlock_t;
|
||||
#include <pthread_locks.h>
|
||||
#elif defined(i386)
|
||||
typedef volatile int lockvar;
|
||||
#ifdef i386
|
||||
#include <x86_locks.h>
|
||||
#endif
|
||||
#if defined(sparc) || defined(__sparc)
|
||||
#elif defined(sparc) || defined(__sparc)
|
||||
typedef volatile int lockvar;
|
||||
#include <sparc_locks.h>
|
||||
#endif
|
||||
#ifdef mips
|
||||
#elif defined(mips)
|
||||
typedef volatile int lockvar;
|
||||
#include <mips_locks.h>
|
||||
#endif
|
||||
#ifdef __alpha
|
||||
#elif defined(__alpha)
|
||||
typedef volatile int lockvar;
|
||||
#include <alpha_locks.h>
|
||||
#endif
|
||||
#else
|
||||
typedef pthread_mutex_t lockvar;
|
||||
typedef pthread_rwlock_t rwlock_t;
|
||||
#include <pthread_locks.h>
|
||||
#endif
|
||||
|
||||
/********************** use an auxiliary function for ranges ************/
|
||||
|
Reference in New Issue
Block a user