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: *
* mods: *
* 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
static char SccsId[] = "%W% %G%";
@ -104,6 +104,7 @@ void
Yap_FreeCodeSpace(char *p)
{
Yap_PrologMode |= MallocMode;
#if INSTRUMENT_MALLOC
if (frees % 1024*4 == 0)
minfo('F');

View File

@ -11,8 +11,11 @@
* File: cdmgr.c *
* 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 $
* Revision 1.184 2006/04/27 14:11:57 rslopes
* *** empty log message ***
*
* Revision 1.183 2006/03/29 16:00:10 vsc
* make tabling compile
*
@ -1629,15 +1632,19 @@ static void expand_consult(void)
return;
}
}
new_cs = new_cl + (InitialConsultCapacity+1);
new_cb = new_cs + (ConsultBase-ConsultSp);
new_cs = new_cl + InitialConsultCapacity;
new_cb = new_cl + ConsultCapacity;
/* 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 */
Yap_FreeCodeSpace((char *)ConsultLow);
/* next, set up pointers correctly */
new_cs += (ConsultSp-ConsultLow);
/* new consult pointer */
ConsultSp = new_cs;
ConsultBase = new_cb;
/* reserve 3 slots for the last elements */
ConsultBase = new_cb-3;
/* new end of memory */
ConsultLow = new_cl;
}
@ -1665,7 +1672,7 @@ not_was_reconsulted(PredEntry *p, Term t, int mode)
}
p->src.OwnerFile = YapConsultingFile();
}
return (TRUE); /* careful */
return TRUE; /* careful */
}
static void

View File

@ -253,6 +253,11 @@ OpDec(int p, char *type, Atom a, Term m)
info->KindOfPE = Ord(OpProperty);
info->NextOfPE = RepAtom(a)->PropsOfAE;
info->OpModule = m;
info->OpName = a;
LOCK(OpListLock);
info->OpNext = OpList;
OpList = info;
UNLOCK(OpListLock);
RepAtom(a)->PropsOfAE = AbsOpProp(info);
INIT_RWLOCK(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_mega_clauses_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;
{
int i;
@ -1184,6 +1190,8 @@ InitCodes(void)
Yap_heap_regs->size_of_overflow = 0;
/* make sure no one else can use these two atoms */
CurrentModule = 0;
OpList = NULL;
Yap_heap_regs->op_list = NULL;
Yap_heap_regs->dead_static_clauses = NULL;
Yap_heap_regs->dead_mega_clauses = NULL;
Yap_heap_regs->dead_static_indices = NULL;

View File

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

View File

@ -128,10 +128,11 @@ typedef struct scanner_extra_alloc {
void *filler;
} ScannerExtraBlock;
/* Problem: we use realloc so we cannot guarantee beforehand pointers will shift or not */
#if USE_SYSTEM_MALLOC
#define EXPAND_TRAIL TRUE
#else
#define EXPAND_TRAIL FALSE
#else
#define EXPAND_TRAIL TRUE
#endif
static char *

View File

@ -11,8 +11,11 @@
* File: stdpreds.c *
* 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 $
* Revision 1.100 2006/02/05 02:26:35 tiagosoares
* MYDDAS: Top Level Functionality
*
* Revision 1.99 2006/02/05 02:17:54 tiagosoares
* MYDDAS: Top Level Functionality
*
@ -1980,7 +1983,6 @@ cont_current_op(void)
{
int prio;
Atom a = AtomOfTerm(EXTRA_CBACK_ARG(3,1));
Int i = IntOfTerm(EXTRA_CBACK_ARG(3,2));
Int fix = IntOfTerm(EXTRA_CBACK_ARG(3,3));
Term TType;
OpEntry *pp = NIL;
@ -1988,6 +1990,7 @@ cont_current_op(void)
AtomEntry *at = RepAtom(a);
if (fix > 3) {
/* starting from an atom */
a = AtomOfTerm(Deref(ARG3));
READ_LOCK(RepAtom(a)->ARWLock);
if (EndOfPAEntr(pp = NextOp(RepOpProp(RepAtom(a)->PropsOfAE)))) {
@ -2018,32 +2021,15 @@ cont_current_op(void)
else
cut_fail();
}
pp = NextOp(RepOpProp(at->PropsOfAE));
if (fix == 3) {
do {
if ((a = at->NextOfAE) == NIL) {
i++;
while (i < AtomHashTableSize) {
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;
EXTRA_CBACK_ARG(3,1) = (CELL) MkAtomTerm(a);
if (pp->OpNext) {
pp = pp->OpNext;
} else {
pp = NextOp(RepOpProp(at->PropsOfAE));
cut_fail();
}
fix = 0;
EXTRA_CBACK_ARG(3,1) = (CELL) MkAtomTerm(at=RepAtom(a=pp->OpName));
}
READ_LOCK(pp->OpRWLock);
if (fix == 0 && pp->Prefix == 0)
@ -2101,15 +2087,12 @@ init_current_op(void)
Yap_Error(TYPE_ERROR_ATOM,top,"current_op/3");
return(FALSE);
}
}
while (TRUE) {
READ_LOCK(HashChain[i].AERWLock);
a = HashChain[i].Entry;
READ_UNLOCK(HashChain[i].AERWLock);
if (a != NIL) {
break;
}
i++;
a = AtomOfTerm(top);
} else {
if (OpList)
a = OpList->OpName;
else
cut_fail();
}
EXTRA_CBACK_ARG(3,1) = (CELL) MkAtomTerm(a);
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;
/*
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
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);
sc = Yap_heap_regs;
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
// if (vsc_count == 218280)
// vsc_xstop = 1;

View File

@ -10,7 +10,7 @@
* File: Heap.h *
* mods: *
* 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 */
@ -201,6 +201,7 @@ typedef struct various_codes {
yamop *expand_clauses_first, *expand_clauses_last;
#if defined(YAPOR) || defined(THREADS)
lockvar expand_clauses_list_lock;
lockvar op_list_lock;
#endif
yamop comma_code[5];
yamop failcode[1];
@ -310,6 +311,7 @@ typedef struct various_codes {
Term module_name[MaxModules];
struct pred_entry *module_pred[MaxModules];
SMALLUNSGN no_of_modules;
struct operator_entry *op_list;
struct static_clause *dead_static_clauses;
struct static_mega_clause *dead_mega_clauses;
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 ExpandClausesLast Yap_heap_regs->expand_clauses_last
#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 FAILCODE Yap_heap_regs->failcode
#define TRUSTFAILCODE Yap_heap_regs->trustfailcode
@ -592,6 +595,7 @@ struct various_codes *Yap_heap_regs;
#define ModuleName Yap_heap_regs->module_name
#define ModulePred Yap_heap_regs->module_pred
#define NoOfModules Yap_heap_regs->no_of_modules
#define OpList Yap_heap_regs->op_list
#define AtomAbol Yap_heap_regs->atom_abol
#define AtomAlarm Yap_heap_regs->atom_alarm
#define AtomAppend Yap_heap_regs->atom_append

View File

@ -10,7 +10,7 @@
* File: Yap.h.m4 *
* mods: *
* 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"
@ -1200,7 +1200,7 @@ extern int Yap_PrologShouldHandleInterrupts;
#elif THREADS
#define YAPEnterCriticalSection() \
{ \
LOCK(BGL); \
/* LOCK(BGL); */ \
Yap_PrologMode |= CritMode; \
}
#define YAPLeaveCriticalSection() \
@ -1214,7 +1214,7 @@ extern int Yap_PrologShouldHandleInterrupts;
Yap_PrologMode &= ~AbortMode; \
Yap_Error(PURE_ABORT, 0, ""); \
} \
UNLOCK(BGL); \
/* UNLOCK(BGL); */ \
}
#else
#define YAPEnterCriticalSection() \

View File

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

View File

@ -11,8 +11,11 @@
* File: rheap.h *
* 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 $
* 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
* fixes to garbage collector
* fixes to debugger
@ -435,6 +438,10 @@ restore_codes(void)
Yap_heap_regs->char_conversion_table2 = (char *)
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) {
StaticClause *sc = PtoStCAdjust(Yap_heap_regs->dead_static_clauses);
Yap_heap_regs->dead_static_clauses = sc;

View File

@ -16,6 +16,9 @@
<h2>Yap-5.1.2:</h2>
<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: ! was not pruning right in p_execute_clause (obs Nicos
Angelopoulos).</li>