fix number of overflow bugs affecting threaded version

make current_op faster.


git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1615 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
vsc 2006-04-28 13:23:23 +00:00
parent a80878d5f6
commit 6fb10bfc51
12 changed files with 96 additions and 67 deletions

View File

@ -12,7 +12,7 @@
* Last rev: * * Last rev: *
* mods: * * mods: *
* comments: allocating space * * comments: allocating space *
* version:$Id: alloc.c,v 1.82 2006-03-24 17:15:18 vsc Exp $ * * version:$Id: alloc.c,v 1.83 2006-04-28 13:23:22 vsc Exp $ *
*************************************************************************/ *************************************************************************/
#ifdef SCCS #ifdef SCCS
static char SccsId[] = "%W% %G%"; static char SccsId[] = "%W% %G%";
@ -104,6 +104,7 @@ void
Yap_FreeCodeSpace(char *p) Yap_FreeCodeSpace(char *p)
{ {
Yap_PrologMode |= MallocMode; Yap_PrologMode |= MallocMode;
#if INSTRUMENT_MALLOC #if INSTRUMENT_MALLOC
if (frees % 1024*4 == 0) if (frees % 1024*4 == 0)
minfo('F'); minfo('F');

View File

@ -11,8 +11,11 @@
* File: cdmgr.c * * File: cdmgr.c *
* comments: Code manager * * comments: Code manager *
* * * *
* Last rev: $Date: 2006-04-27 14:11:57 $,$Author: rslopes $ * * Last rev: $Date: 2006-04-28 13:23:22 $,$Author: vsc $ *
* $Log: not supported by cvs2svn $ * $Log: not supported by cvs2svn $
* Revision 1.184 2006/04/27 14:11:57 rslopes
* *** empty log message ***
*
* Revision 1.183 2006/03/29 16:00:10 vsc * Revision 1.183 2006/03/29 16:00:10 vsc
* make tabling compile * make tabling compile
* *
@ -1629,15 +1632,19 @@ static void expand_consult(void)
return; return;
} }
} }
new_cs = new_cl + (InitialConsultCapacity+1); new_cs = new_cl + InitialConsultCapacity;
new_cb = new_cs + (ConsultBase-ConsultSp); new_cb = new_cl + ConsultCapacity;
/* start copying */ /* start copying */
memcpy((void *)(new_cs), (void *)(ConsultSp), OldConsultCapacity*sizeof(consult_obj)); memcpy((void *)new_cs, (void *)ConsultLow, OldConsultCapacity*sizeof(consult_obj));
/* copying done, release old space */ /* copying done, release old space */
Yap_FreeCodeSpace((char *)ConsultLow); Yap_FreeCodeSpace((char *)ConsultLow);
/* next, set up pointers correctly */ /* next, set up pointers correctly */
new_cs += (ConsultSp-ConsultLow);
/* new consult pointer */
ConsultSp = new_cs; ConsultSp = new_cs;
ConsultBase = new_cb; /* reserve 3 slots for the last elements */
ConsultBase = new_cb-3;
/* new end of memory */
ConsultLow = new_cl; ConsultLow = new_cl;
} }
@ -1665,7 +1672,7 @@ not_was_reconsulted(PredEntry *p, Term t, int mode)
} }
p->src.OwnerFile = YapConsultingFile(); p->src.OwnerFile = YapConsultingFile();
} }
return (TRUE); /* careful */ return TRUE; /* careful */
} }
static void static void

View File

@ -253,6 +253,11 @@ OpDec(int p, char *type, Atom a, Term m)
info->KindOfPE = Ord(OpProperty); info->KindOfPE = Ord(OpProperty);
info->NextOfPE = RepAtom(a)->PropsOfAE; info->NextOfPE = RepAtom(a)->PropsOfAE;
info->OpModule = m; info->OpModule = m;
info->OpName = a;
LOCK(OpListLock);
info->OpNext = OpList;
OpList = info;
UNLOCK(OpListLock);
RepAtom(a)->PropsOfAE = AbsOpProp(info); RepAtom(a)->PropsOfAE = AbsOpProp(info);
INIT_RWLOCK(info->OpRWLock); INIT_RWLOCK(info->OpRWLock);
WRITE_LOCK(info->OpRWLock); WRITE_LOCK(info->OpRWLock);
@ -953,6 +958,7 @@ InitCodes(void)
INIT_LOCK(Yap_heap_regs->dead_static_clauses_lock); INIT_LOCK(Yap_heap_regs->dead_static_clauses_lock);
INIT_LOCK(Yap_heap_regs->dead_mega_clauses_lock); INIT_LOCK(Yap_heap_regs->dead_mega_clauses_lock);
INIT_LOCK(Yap_heap_regs->dead_static_indices_lock); INIT_LOCK(Yap_heap_regs->dead_static_indices_lock);
INIT_LOCK(Yap_heap_regs->op_list_lock);
Yap_heap_regs->heap_top_owner = -1; Yap_heap_regs->heap_top_owner = -1;
{ {
int i; int i;
@ -1184,6 +1190,8 @@ InitCodes(void)
Yap_heap_regs->size_of_overflow = 0; Yap_heap_regs->size_of_overflow = 0;
/* make sure no one else can use these two atoms */ /* make sure no one else can use these two atoms */
CurrentModule = 0; CurrentModule = 0;
OpList = NULL;
Yap_heap_regs->op_list = NULL;
Yap_heap_regs->dead_static_clauses = NULL; Yap_heap_regs->dead_static_clauses = NULL;
Yap_heap_regs->dead_mega_clauses = NULL; Yap_heap_regs->dead_mega_clauses = NULL;
Yap_heap_regs->dead_static_indices = NULL; Yap_heap_regs->dead_static_indices = NULL;

View File

@ -4481,9 +4481,9 @@ static Int
p_format(void) p_format(void)
{ /* 'format'(Control,Args) */ { /* 'format'(Control,Args) */
Int res; Int res;
LOCK(BGL); //LOCK(BGL);
res = format(Deref(ARG1),Deref(ARG2), Yap_c_output_stream); res = format(Deref(ARG1),Deref(ARG2), Yap_c_output_stream);
UNLOCK(BGL); //UNLOCK(BGL);
return res; return res;
} }
@ -4494,17 +4494,17 @@ p_format2(void)
int old_c_stream = Yap_c_output_stream; int old_c_stream = Yap_c_output_stream;
Int out; Int out;
LOCK(BGL); //LOCK(BGL);
/* needs to change Yap_c_output_stream for write */ /* needs to change Yap_c_output_stream for write */
Yap_c_output_stream = CheckStream (ARG1, Output_Stream_f, "format/3"); Yap_c_output_stream = CheckStream (ARG1, Output_Stream_f, "format/3");
if (Yap_c_output_stream == -1) { if (Yap_c_output_stream == -1) {
Yap_c_output_stream = old_c_stream; Yap_c_output_stream = old_c_stream;
UNLOCK(BGL); //UNLOCK(BGL);
return(FALSE); return(FALSE);
} }
out = format(Deref(ARG2),Deref(ARG3),Yap_c_output_stream); out = format(Deref(ARG2),Deref(ARG3),Yap_c_output_stream);
Yap_c_output_stream = old_c_stream; Yap_c_output_stream = old_c_stream;
UNLOCK(BGL); // UNLOCK(BGL);
return(out); return(out);
} }

View File

@ -128,10 +128,11 @@ typedef struct scanner_extra_alloc {
void *filler; void *filler;
} ScannerExtraBlock; } ScannerExtraBlock;
/* Problem: we use realloc so we cannot guarantee beforehand pointers will shift or not */
#if USE_SYSTEM_MALLOC #if USE_SYSTEM_MALLOC
#define EXPAND_TRAIL TRUE
#else
#define EXPAND_TRAIL FALSE #define EXPAND_TRAIL FALSE
#else
#define EXPAND_TRAIL TRUE
#endif #endif
static char * static char *
@ -155,7 +156,7 @@ AllocScannerMemory(unsigned int size)
if (size > alloc_size) if (size > alloc_size)
alloc_size = size; alloc_size = size;
if(!EXPAND_TRAIL || !Yap_growtrail (alloc_size, TRUE)) { if(!EXPAND_TRAIL || !Yap_growtrail(alloc_size, TRUE)) {
struct scanner_extra_alloc *ptr; struct scanner_extra_alloc *ptr;
if (!(ptr = (struct scanner_extra_alloc *)malloc(size+sizeof(ScannerExtraBlock)))) { if (!(ptr = (struct scanner_extra_alloc *)malloc(size+sizeof(ScannerExtraBlock)))) {

View File

@ -11,8 +11,11 @@
* File: stdpreds.c * * File: stdpreds.c *
* comments: General-purpose C implemented system predicates * * comments: General-purpose C implemented system predicates *
* * * *
* Last rev: $Date: 2006-02-05 02:26:35 $,$Author: tiagosoares $ * * Last rev: $Date: 2006-04-28 13:23:23 $,$Author: vsc $ *
* $Log: not supported by cvs2svn $ * $Log: not supported by cvs2svn $
* Revision 1.100 2006/02/05 02:26:35 tiagosoares
* MYDDAS: Top Level Functionality
*
* Revision 1.99 2006/02/05 02:17:54 tiagosoares * Revision 1.99 2006/02/05 02:17:54 tiagosoares
* MYDDAS: Top Level Functionality * MYDDAS: Top Level Functionality
* *
@ -1980,7 +1983,6 @@ cont_current_op(void)
{ {
int prio; int prio;
Atom a = AtomOfTerm(EXTRA_CBACK_ARG(3,1)); Atom a = AtomOfTerm(EXTRA_CBACK_ARG(3,1));
Int i = IntOfTerm(EXTRA_CBACK_ARG(3,2));
Int fix = IntOfTerm(EXTRA_CBACK_ARG(3,3)); Int fix = IntOfTerm(EXTRA_CBACK_ARG(3,3));
Term TType; Term TType;
OpEntry *pp = NIL; OpEntry *pp = NIL;
@ -1988,6 +1990,7 @@ cont_current_op(void)
AtomEntry *at = RepAtom(a); AtomEntry *at = RepAtom(a);
if (fix > 3) { if (fix > 3) {
/* starting from an atom */
a = AtomOfTerm(Deref(ARG3)); a = AtomOfTerm(Deref(ARG3));
READ_LOCK(RepAtom(a)->ARWLock); READ_LOCK(RepAtom(a)->ARWLock);
if (EndOfPAEntr(pp = NextOp(RepOpProp(RepAtom(a)->PropsOfAE)))) { if (EndOfPAEntr(pp = NextOp(RepOpProp(RepAtom(a)->PropsOfAE)))) {
@ -2018,32 +2021,15 @@ cont_current_op(void)
else else
cut_fail(); cut_fail();
} }
pp = NextOp(RepOpProp(at->PropsOfAE));
if (fix == 3) { if (fix == 3) {
do { if (pp->OpNext) {
if ((a = at->NextOfAE) == NIL) { pp = pp->OpNext;
i++; } else {
while (i < AtomHashTableSize) { cut_fail();
READ_LOCK(HashChain[i].AERWLock); }
a = HashChain[i].Entry;
READ_UNLOCK(HashChain[i].AERWLock);
if (a != NIL) {
break;
}
i++;
}
if (i == AtomHashTableSize)
cut_fail();
EXTRA_CBACK_ARG(3,2) = (CELL) MkIntTerm(i);
}
at = RepAtom(a);
READ_LOCK(at->ARWLock);
pp = NextOp(RepOpProp(at->PropsOfAE));
READ_UNLOCK(at->ARWLock);
} while (EndOfPAEntr(pp));
fix = 0; fix = 0;
EXTRA_CBACK_ARG(3,1) = (CELL) MkAtomTerm(a); EXTRA_CBACK_ARG(3,1) = (CELL) MkAtomTerm(at=RepAtom(a=pp->OpName));
} else {
pp = NextOp(RepOpProp(at->PropsOfAE));
} }
READ_LOCK(pp->OpRWLock); READ_LOCK(pp->OpRWLock);
if (fix == 0 && pp->Prefix == 0) if (fix == 0 && pp->Prefix == 0)
@ -2101,15 +2087,12 @@ init_current_op(void)
Yap_Error(TYPE_ERROR_ATOM,top,"current_op/3"); Yap_Error(TYPE_ERROR_ATOM,top,"current_op/3");
return(FALSE); return(FALSE);
} }
} a = AtomOfTerm(top);
while (TRUE) { } else {
READ_LOCK(HashChain[i].AERWLock); if (OpList)
a = HashChain[i].Entry; a = OpList->OpName;
READ_UNLOCK(HashChain[i].AERWLock); else
if (a != NIL) { cut_fail();
break;
}
i++;
} }
EXTRA_CBACK_ARG(3,1) = (CELL) MkAtomTerm(a); EXTRA_CBACK_ARG(3,1) = (CELL) MkAtomTerm(a);
EXTRA_CBACK_ARG(3,2) = (CELL) MkIntTerm(i); EXTRA_CBACK_ARG(3,2) = (CELL) MkIntTerm(i);

View File

@ -126,6 +126,30 @@ jmp_deb(int i) {if (i) printf("Here we go\n"); else jmp_deb(0);}
struct various_codes *sc; struct various_codes *sc;
/*
CELL array[332];
int found = FALSE;
static void
check_area(void)
{
int i, first = -1;
for (i= 0; i < 332; i++) {
if (array[i] !=((CELL *)0x187a800)[i]) {
if (first != -1) {
first = i;
found = TRUE;
}
fprintf(stderr,"%lld changed %d\n",vsc_count,i);
}
array[i] = ((CELL *)0x187a800)[i];
}
if (first != -1)
jmp_deb(i);
}
*/
void void
low_level_trace(yap_low_level_port port, PredEntry *pred, CELL *args) low_level_trace(yap_low_level_port port, PredEntry *pred, CELL *args)
{ {
@ -137,17 +161,6 @@ low_level_trace(yap_low_level_port port, PredEntry *pred, CELL *args)
LOCK(Yap_heap_regs->low_level_trace_lock); LOCK(Yap_heap_regs->low_level_trace_lock);
sc = Yap_heap_regs; sc = Yap_heap_regs;
vsc_count++; vsc_count++;
// if (vsc_count < 13600) {
// UNLOCK(Yap_heap_regs->low_level_trace_lock);
// return;
// }
if (vsc_count == 22965LL) {
jmp_deb(1);
}
if (vsc_count < 1468068888) {
UNLOCK(Yap_heap_regs->low_level_trace_lock);
return;
}
#ifdef COMMENTED #ifdef COMMENTED
// if (vsc_count == 218280) // if (vsc_count == 218280)
// vsc_xstop = 1; // vsc_xstop = 1;

View File

@ -10,7 +10,7 @@
* File: Heap.h * * File: Heap.h *
* mods: * * mods: *
* comments: Heap Init Structure * * comments: Heap Init Structure *
* version: $Id: Heap.h,v 1.95 2006-04-27 14:13:24 rslopes Exp $ * * version: $Id: Heap.h,v 1.96 2006-04-28 13:23:23 vsc Exp $ *
*************************************************************************/ *************************************************************************/
/* information that can be stored in Code Space */ /* information that can be stored in Code Space */
@ -201,6 +201,7 @@ typedef struct various_codes {
yamop *expand_clauses_first, *expand_clauses_last; yamop *expand_clauses_first, *expand_clauses_last;
#if defined(YAPOR) || defined(THREADS) #if defined(YAPOR) || defined(THREADS)
lockvar expand_clauses_list_lock; lockvar expand_clauses_list_lock;
lockvar op_list_lock;
#endif #endif
yamop comma_code[5]; yamop comma_code[5];
yamop failcode[1]; yamop failcode[1];
@ -310,6 +311,7 @@ typedef struct various_codes {
Term module_name[MaxModules]; Term module_name[MaxModules];
struct pred_entry *module_pred[MaxModules]; struct pred_entry *module_pred[MaxModules];
SMALLUNSGN no_of_modules; SMALLUNSGN no_of_modules;
struct operator_entry *op_list;
struct static_clause *dead_static_clauses; struct static_clause *dead_static_clauses;
struct static_mega_clause *dead_mega_clauses; struct static_mega_clause *dead_mega_clauses;
struct static_index *dead_static_indices; struct static_index *dead_static_indices;
@ -541,6 +543,7 @@ struct various_codes *Yap_heap_regs;
#define ExpandClausesFirst Yap_heap_regs->expand_clauses_first #define ExpandClausesFirst Yap_heap_regs->expand_clauses_first
#define ExpandClausesLast Yap_heap_regs->expand_clauses_last #define ExpandClausesLast Yap_heap_regs->expand_clauses_last
#define ExpandClausesListLock Yap_heap_regs->expand_clauses_list_lock #define ExpandClausesListLock Yap_heap_regs->expand_clauses_list_lock
#define OpListLock Yap_heap_regs->op_list_lock
#define COMMA_CODE Yap_heap_regs->comma_code #define COMMA_CODE Yap_heap_regs->comma_code
#define FAILCODE Yap_heap_regs->failcode #define FAILCODE Yap_heap_regs->failcode
#define TRUSTFAILCODE Yap_heap_regs->trustfailcode #define TRUSTFAILCODE Yap_heap_regs->trustfailcode
@ -592,6 +595,7 @@ struct various_codes *Yap_heap_regs;
#define ModuleName Yap_heap_regs->module_name #define ModuleName Yap_heap_regs->module_name
#define ModulePred Yap_heap_regs->module_pred #define ModulePred Yap_heap_regs->module_pred
#define NoOfModules Yap_heap_regs->no_of_modules #define NoOfModules Yap_heap_regs->no_of_modules
#define OpList Yap_heap_regs->op_list
#define AtomAbol Yap_heap_regs->atom_abol #define AtomAbol Yap_heap_regs->atom_abol
#define AtomAlarm Yap_heap_regs->atom_alarm #define AtomAlarm Yap_heap_regs->atom_alarm
#define AtomAppend Yap_heap_regs->atom_append #define AtomAppend Yap_heap_regs->atom_append

View File

@ -10,7 +10,7 @@
* File: Yap.h.m4 * * File: Yap.h.m4 *
* mods: * * mods: *
* comments: main header file for YAP * * comments: main header file for YAP *
* version: $Id: Yap.h,v 1.14 2006-04-13 12:02:39 rslopes Exp $ * * version: $Id: Yap.h,v 1.15 2006-04-28 13:23:23 vsc Exp $ *
*************************************************************************/ *************************************************************************/
#include "config.h" #include "config.h"
@ -1200,7 +1200,7 @@ extern int Yap_PrologShouldHandleInterrupts;
#elif THREADS #elif THREADS
#define YAPEnterCriticalSection() \ #define YAPEnterCriticalSection() \
{ \ { \
LOCK(BGL); \ /* LOCK(BGL); */ \
Yap_PrologMode |= CritMode; \ Yap_PrologMode |= CritMode; \
} }
#define YAPLeaveCriticalSection() \ #define YAPLeaveCriticalSection() \
@ -1214,7 +1214,7 @@ extern int Yap_PrologShouldHandleInterrupts;
Yap_PrologMode &= ~AbortMode; \ Yap_PrologMode &= ~AbortMode; \
Yap_Error(PURE_ABORT, 0, ""); \ Yap_Error(PURE_ABORT, 0, ""); \
} \ } \
UNLOCK(BGL); \ /* UNLOCK(BGL); */ \
} }
#else #else
#define YAPEnterCriticalSection() \ #define YAPEnterCriticalSection() \

View File

@ -261,14 +261,16 @@ IsModProperty (int flags)
/* operator property entry structure */ /* operator property entry structure */
typedef struct typedef struct operator_entry
{ {
Prop NextOfPE; /* used to chain properties */ Prop NextOfPE; /* used to chain properties */
PropFlags KindOfPE; /* kind of property */ PropFlags KindOfPE; /* kind of property */
#if defined(YAPOR) || defined(THREADS) #if defined(YAPOR) || defined(THREADS)
rwlock_t OpRWLock; /* a read-write lock to protect the entry */ rwlock_t OpRWLock; /* a read-write lock to protect the entry */
#endif #endif
Atom OpName; /* atom name */
Term OpModule; /* module of predicate */ Term OpModule; /* module of predicate */
struct operator_entry *OpNext; /* next in list of operators */
BITS16 Prefix, Infix, Posfix; /* precedences */ BITS16 Prefix, Infix, Posfix; /* precedences */
} OpEntry; } OpEntry;
#if USE_OFFSETS_IN_PROPS #if USE_OFFSETS_IN_PROPS

View File

@ -11,8 +11,11 @@
* File: rheap.h * * File: rheap.h *
* comments: walk through heap code * * comments: walk through heap code *
* * * *
* Last rev: $Date: 2006-03-22 20:07:28 $,$Author: vsc $ * * Last rev: $Date: 2006-04-28 13:23:23 $,$Author: vsc $ *
* $Log: not supported by cvs2svn $ * $Log: not supported by cvs2svn $
* Revision 1.64 2006/03/22 20:07:28 vsc
* take better care of zombies
*
* Revision 1.63 2006/03/06 14:04:56 vsc * Revision 1.63 2006/03/06 14:04:56 vsc
* fixes to garbage collector * fixes to garbage collector
* fixes to debugger * fixes to debugger
@ -435,6 +438,10 @@ restore_codes(void)
Yap_heap_regs->char_conversion_table2 = (char *) Yap_heap_regs->char_conversion_table2 = (char *)
AddrAdjust((ADDR)Yap_heap_regs->char_conversion_table2); AddrAdjust((ADDR)Yap_heap_regs->char_conversion_table2);
} }
if (Yap_heap_regs->op_list) {
Yap_heap_regs->op_list = (struct operator_entry *)
AddrAdjust((ADDR)Yap_heap_regs->op_list);
}
if (Yap_heap_regs->dead_static_clauses) { if (Yap_heap_regs->dead_static_clauses) {
StaticClause *sc = PtoStCAdjust(Yap_heap_regs->dead_static_clauses); StaticClause *sc = PtoStCAdjust(Yap_heap_regs->dead_static_clauses);
Yap_heap_regs->dead_static_clauses = sc; Yap_heap_regs->dead_static_clauses = sc;

View File

@ -16,6 +16,9 @@
<h2>Yap-5.1.2:</h2> <h2>Yap-5.1.2:</h2>
<ul> <ul>
<li> FIXED: make current_op only walk over atoms.</li>
<li> FIXED: memory corruption when copying consult stack (obs Paulo Moura).</li>
<li> FIXED: get rid of some silly locks.</li>
<li> FIXED: don't compare block top with <= (obs Paulo Moura).</li> <li> FIXED: don't compare block top with <= (obs Paulo Moura).</li>
<li> FIXED: ! was not pruning right in p_execute_clause (obs Nicos <li> FIXED: ! was not pruning right in p_execute_clause (obs Nicos
Angelopoulos).</li> Angelopoulos).</li>