fix nil pointer in prolog profiler
This commit is contained in:
parent
b28deedffe
commit
e5891afe44
@ -1024,6 +1024,8 @@ static void spy_goal(USES_REGS1) {
|
||||
}
|
||||
/* standard profiler */
|
||||
if ((pe->PredFlags & ProfiledPredFlag)) {
|
||||
if (!pe->StatisticsForPred)
|
||||
Yap_initProfiler(pe);
|
||||
LOCK(pe->StatisticsForPred->lock);
|
||||
pe->StatisticsForPred->NOfEntries++;
|
||||
UNLOCK(pe->StatisticsForPred->lock);
|
||||
|
@ -112,7 +112,7 @@ Functor Yap_MkFunctor(Atom ap, arity_t arity) {
|
||||
WRITE_LOCK(ae->ARWLock);
|
||||
f = InlinedUnlockedMkFunctor(ae, arity);
|
||||
WRITE_UNLOCK(ae->ARWLock);
|
||||
return (f);
|
||||
return f;
|
||||
}
|
||||
|
||||
/* vsc: We must guarantee that IsVarTerm(functor) returns true! */
|
||||
@ -818,6 +818,7 @@ Prop Yap_NewPredPropByFunctor(FunctorEntry *fe, Term cur_mod) {
|
||||
p->ModuleOfPred = 0L;
|
||||
else
|
||||
p->ModuleOfPred = cur_mod;
|
||||
p->StatisticsForPred = NULL;
|
||||
Yap_NewModulePred(cur_mod, p);
|
||||
|
||||
#ifdef TABLING
|
||||
@ -887,6 +888,7 @@ Prop Yap_NewThreadPred(PredEntry *ap USES_REGS) {
|
||||
return NIL;
|
||||
}
|
||||
INIT_LOCK(p->PELock);
|
||||
p->StatisticsForPred = NULL:
|
||||
p->KindOfPE = PEProp;
|
||||
p->ArityOfPE = ap->ArityOfPE;
|
||||
p->cs.p_code.FirstClause = p->cs.p_code.LastClause = NULL;
|
||||
@ -941,6 +943,7 @@ Prop Yap_NewPredPropByAtom(AtomEntry *ae, Term cur_mod) {
|
||||
INIT_LOCK(p->PELock);
|
||||
p->KindOfPE = PEProp;
|
||||
p->ArityOfPE = 0;
|
||||
p->StatisticsForPred = NULL;
|
||||
p->cs.p_code.FirstClause = p->cs.p_code.LastClause = NULL;
|
||||
p->cs.p_code.NOfClauses = 0;
|
||||
p->PredFlags = 0L;
|
||||
|
26
C/amasm.c
26
C/amasm.c
@ -282,17 +282,15 @@ static void a_fetch_cv(cmp_op_info *, int, struct intermediates *);
|
||||
static void a_fetch_vc(cmp_op_info *, int, struct intermediates *);
|
||||
static yamop *a_f2(cmp_op_info *, yamop *, int, struct intermediates *);
|
||||
|
||||
static profile_data *
|
||||
initProfiler(PredEntry *p, struct intermediates *cip)
|
||||
profile_data *
|
||||
Yap_initProfiler(PredEntry *p)
|
||||
{
|
||||
profile_data *ptr;
|
||||
if (p->StatisticsForPred)
|
||||
return p->StatisticsForPred;
|
||||
if ((ptr = (profile_data *)Yap_AllocCodeSpace(sizeof(profile_data ))) == NULL) {
|
||||
/* OOOPS, got in trouble, must do a longjmp and recover space */
|
||||
save_machine_regs();
|
||||
siglongjmp(cip->CompilerBotch,2);
|
||||
}
|
||||
if (!ptr)
|
||||
return NULL;
|
||||
}
|
||||
INIT_LOCK(ptr->lock);
|
||||
ptr->NOfEntries = 0;
|
||||
ptr->NOfHeadSuccesses = 0;
|
||||
@ -2010,7 +2008,7 @@ a_try(op_numbers opcode, CELL lab, CELL opr, int nofalts, int hascut, yamop *cod
|
||||
if (ap->PredFlags & CountPredFlag)
|
||||
newcp->opc = emit_op(_count_retry_logical);
|
||||
else if (ap->PredFlags & ProfiledPredFlag) {
|
||||
if (!initProfiler(ap, cip)) {
|
||||
if (!Yap_initProfiler(ap)) {
|
||||
return NULL;
|
||||
}
|
||||
newcp->opc = emit_op(_profiled_retry_logical);
|
||||
@ -2019,15 +2017,16 @@ a_try(op_numbers opcode, CELL lab, CELL opr, int nofalts, int hascut, yamop *cod
|
||||
newcp->y_u.OtaLl.s = emit_count(opr);
|
||||
} else {
|
||||
/* trust */
|
||||
if (ap->PredFlags & CountPredFlag)
|
||||
if (ap->PredFlags & CountPredFlag) {
|
||||
newcp->opc = emit_op(_count_trust_logical);
|
||||
else if (ap->PredFlags & ProfiledPredFlag) {
|
||||
if (!initProfiler(ap, cip)) {
|
||||
} else if (ap->PredFlags & ProfiledPredFlag) {
|
||||
if (!Yap_initProfiler(ap)) {
|
||||
return NULL;
|
||||
}
|
||||
newcp->opc = emit_op(_profiled_trust_logical);
|
||||
} else
|
||||
} else {
|
||||
newcp->opc = emit_op(_trust_logical);
|
||||
}
|
||||
newcp->y_u.OtILl.block = (LogUpdIndex *)(cip->code_addr);
|
||||
*cip->current_trust_lab = newcp;
|
||||
}
|
||||
@ -3664,11 +3663,12 @@ do_pass(int pass_no, yamop **entry_codep, int assembling, int *clause_has_blobsp
|
||||
if ((pe->PredFlags & (CPredFlag|UserCPredFlag|AsmPredFlag)) ||
|
||||
!pe->ModuleOfPred) {
|
||||
code_p = a_pl(_enter_profiling, pe, code_p, pass_no);
|
||||
Yap_initProfiler(pe);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case retry_profiled_op:
|
||||
if (!initProfiler(cip->CurrentPred, cip)) {
|
||||
if (!Yap_initProfiler(cip->CurrentPred)) {
|
||||
return NULL;
|
||||
}
|
||||
code_p = a_pl(_retry_profiled, (PredEntry *)(cip->cpc->rnd1), code_p, pass_no);
|
||||
|
12
C/cdmgr.c
12
C/cdmgr.c
@ -409,6 +409,9 @@ static void IPred(PredEntry *ap, UInt NSlots, yamop *next_pc) {
|
||||
ap->PredFlags |= IndexedPredFlag;
|
||||
}
|
||||
if (ap->PredFlags & (SpiedPredFlag | CountPredFlag | ProfiledPredFlag)) {
|
||||
if (ap->PredFlags & ProfiledPredFlag) {
|
||||
Yap_initProfiler(ap);
|
||||
}
|
||||
ap->OpcodeOfPred = Yap_opcode(_spy_pred);
|
||||
ap->CodeOfPred = (yamop *)(&(ap->OpcodeOfPred));
|
||||
#if defined(YAPOR) || defined(THREADS)
|
||||
@ -980,6 +983,9 @@ static void retract_all(PredEntry *p, int in_use) {
|
||||
p->cs.p_code.TrueCodeOfPred = p->CodeOfPred = (yamop *)(&(p->OpcodeOfPred));
|
||||
if (trueGlobalPrologFlag(PROFILING_FLAG)) {
|
||||
p->PredFlags |= ProfiledPredFlag;
|
||||
if (!Yap_initProfiler(p)) {
|
||||
return;
|
||||
}
|
||||
} else
|
||||
p->PredFlags &= ~ProfiledPredFlag;
|
||||
if (CALL_COUNTING) {
|
||||
@ -1044,6 +1050,9 @@ static void add_first_static(PredEntry *p, yamop *cp, int spy_flag) {
|
||||
p->cs.p_code.NOfClauses = 1;
|
||||
if (trueGlobalPrologFlag(PROFILING_FLAG)) {
|
||||
p->PredFlags |= ProfiledPredFlag;
|
||||
if (!Yap_initProfiler(p)) {
|
||||
return;
|
||||
}
|
||||
spy_flag = TRUE;
|
||||
} else {
|
||||
p->PredFlags &= ~ProfiledPredFlag;
|
||||
@ -1072,6 +1081,9 @@ static void add_first_dynamic(PredEntry *p, yamop *cp, int spy_flag) {
|
||||
|
||||
if (trueGlobalPrologFlag(PROFILING_FLAG)) {
|
||||
p->PredFlags |= ProfiledPredFlag;
|
||||
if (!Yap_initProfiler(p)) {
|
||||
return;
|
||||
}
|
||||
spy_flag = true;
|
||||
} else {
|
||||
p->PredFlags &= ~ProfiledPredFlag;
|
||||
|
@ -1413,9 +1413,9 @@ c_functor(Term Goal, Term mod, compiler_struct *cglobs)
|
||||
save_machine_regs();
|
||||
siglongjmp(cglobs->cint.CompilerBotch, OUT_OF_HEAP_BOTCH);
|
||||
}
|
||||
if (profiling)
|
||||
if (profiling) {
|
||||
Yap_emit(enter_profiling_op, (CELL)RepPredProp(p0), Zero, &cglobs->cint);
|
||||
else if (call_counting)
|
||||
} else if (call_counting)
|
||||
Yap_emit(count_call_op, (CELL)RepPredProp(p0), Zero, &cglobs->cint);
|
||||
c_args(Goal, 0, cglobs);
|
||||
Yap_emit(safe_call_op, (CELL)p0 , Zero, &cglobs->cint);
|
||||
|
14
C/dbase.c
14
C/dbase.c
@ -2681,6 +2681,11 @@ static PredEntry *new_lu_int_key(Int key) {
|
||||
p->ArityOfPE = 3;
|
||||
p->OpcodeOfPred = Yap_opcode(_op_fail);
|
||||
p->cs.p_code.TrueCodeOfPred = p->CodeOfPred = FAILCODE;
|
||||
if (p->PredFlags & ProfiledPredFlag) {
|
||||
if (!Yap_initProfiler(p)) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
INT_LU_KEYS[hash_key] = p0;
|
||||
return p;
|
||||
}
|
||||
@ -2714,6 +2719,11 @@ static PredEntry *new_lu_entry(Term t) {
|
||||
if (CurrentModule == PROLOG_MODULE)
|
||||
pe->PredFlags |= StandardPredFlag;
|
||||
pe->cs.p_code.TrueCodeOfPred = pe->CodeOfPred = FAILCODE;
|
||||
if (pe->PredFlags & ProfiledPredFlag) {
|
||||
if (!Yap_initProfiler(pe)) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return pe;
|
||||
}
|
||||
|
||||
@ -2738,7 +2748,8 @@ static DBProp find_entry(Term t) {
|
||||
at = AtomDot;
|
||||
arity = 2;
|
||||
}
|
||||
return RepDBProp(FindDBProp(RepAtom(at), 0, arity, 0));
|
||||
DBProp rc = RepDBProp(FindDBProp(RepAtom(at), 0, arity, 0));
|
||||
return rc;
|
||||
}
|
||||
|
||||
static PredEntry *find_lu_entry(Term t) {
|
||||
@ -3304,6 +3315,7 @@ static Int lu_recorded(PredEntry *pe USES_REGS) {
|
||||
}
|
||||
if (pe->PredFlags & ProfiledPredFlag) {
|
||||
LOCK(pe->StatisticsForPred->lock);
|
||||
|
||||
pe->StatisticsForPred->NOfEntries++;
|
||||
UNLOCK(pe->StatisticsForPred->lock);
|
||||
}
|
||||
|
Reference in New Issue
Block a user