updates to gprof

support for __POWER__
Try to saveregs before longjmp.


git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1485 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
vsc 2005-12-23 00:20:14 +00:00
parent 208237d667
commit f5002fa37f
13 changed files with 242 additions and 99 deletions

View File

@ -10,8 +10,12 @@
* *
* File: absmi.c *
* comments: Portable abstract machine interpreter *
* Last rev: $Date: 2005-12-17 03:25:38 $,$Author: vsc $ *
* Last rev: $Date: 2005-12-23 00:20:13 $,$Author: vsc $ *
* $Log: not supported by cvs2svn $
* Revision 1.189 2005/12/17 03:25:38 vsc
* major changes to support online event-based profiling
* improve error discovery and restart on scanner.
*
* Revision 1.188 2005/12/05 17:16:10 vsc
* write_depth/3
* overflow handlings and garbage collection
@ -524,12 +528,10 @@ Yap_absmi(int inp)
setregs();
CACHE_A1();
reset_absmi:
#if !S_IN_MEM
CACHE_A1();
#endif
SP = SP0;
#if USE_THREADED_CODE
@ -582,6 +584,7 @@ Yap_absmi(int inp)
FAIL();
}
setregs();
CACHE_A1();
goto reset_absmi;
#if !OS_HANDLES_TR_OVERFLOW
@ -1037,10 +1040,11 @@ Yap_absmi(int inp)
#endif
ipc = Yap_CleanUpIndex(PREG->u.Ill.I);
setregs();
/* restart index */
PREG = ipc;
UNLOCK(pe->PELock);
if (PREG == NULL) FAIL();
/* restart index */
if (ipc == NULL) FAIL();
PREG = ipc;
save_pc();
CACHE_A1();
JMPNext();
}
@ -1109,6 +1113,7 @@ Yap_absmi(int inp)
UNLOCK(lcl->ClLock);
}
PREG = Yap_ErLogUpdIndex(cl, PREG);
save_pc();
} else {
UNLOCK(cl->ClLock);
}
@ -1129,6 +1134,7 @@ Yap_absmi(int inp)
}
}
PREG = Yap_ErLogUpdIndex(cl, PREG);
save_pc();
}
}
#endif
@ -1312,6 +1318,8 @@ Yap_absmi(int inp)
anything yet */
READ_UNLOCK(((PredEntry *)(PREG->u.ld.p))->PRWLock);
PREG = PREG->u.ld.p->CodeOfPred;
/* for profiler */
save_pc();
JMPNext();
}
#endif
@ -1461,6 +1469,7 @@ Yap_absmi(int inp)
}
#endif
PREG = B->cp_ap;
save_pc();
CACHE_TR(B->cp_tr);
PREFETCH_OP(PREG);
failloop:
@ -2149,6 +2158,8 @@ Yap_absmi(int inp)
check_stack(NoStackExecute, H);
#endif
PREG = pt0->CodeOfPred;
/* for profiler */
save_pc();
ENV_YREG[E_CB] = d0;
ENDD(d0);
#ifdef DEPTH_LIMIT
@ -2209,6 +2220,8 @@ Yap_absmi(int inp)
DEPTH -= MkIntConstant(2);
#endif /* DEPTH_LIMIT */
PREG = pt0->CodeOfPred;
/* for profiler */
save_pc();
ALWAYS_LOOKAHEAD(pt0->OpcodeOfPred);
/* do deallocate */
CPREG = (yamop *) ENV_YREG[E_CP];
@ -2269,6 +2282,8 @@ Yap_absmi(int inp)
CPREG = NEXTOP(PREG, sla);
ALWAYS_LOOKAHEAD(pt->OpcodeOfPred);
PREG = pt->CodeOfPred;
/* for profiler */
save_pc();
#ifdef DEPTH_LIMIT
if (DEPTH <= MkIntTerm(1)) {/* I assume Module==0 is primitives */
if (pt->ModuleOfPred) {
@ -2318,6 +2333,8 @@ Yap_absmi(int inp)
CPREG = NEXTOP(PREG, sla);
ALWAYS_LOOKAHEAD(ap->OpcodeOfPred);
PREG = ap->CodeOfPred;
/* for profiler */
save_pc();
check_depth(DEPTH, ap);
#ifdef FROZEN_STACKS
{
@ -2535,6 +2552,8 @@ Yap_absmi(int inp)
CACHE_A1();
check_depth(DEPTH, ap);
PREG = ap->CodeOfPred;
/* for profiler */
save_pc();
ALWAYS_LOOKAHEAD(ap->OpcodeOfPred);
/* do deallocate */
CPREG = (yamop *) ENV_YREG[E_CP];
@ -2728,12 +2747,16 @@ Yap_absmi(int inp)
low_level_trace(enter_pred,(PredEntry *)(SREG),XREGS+1);
#endif /* LOW_LEVEL_TRACE */
PREG = ((PredEntry *)(SREG))->CodeOfPred;
/* for profiler */
save_pc();
CACHE_A1();
JMPNext();
BOp(procceed, p);
CACHE_Y_AS_ENV(YREG);
PREG = CPREG;
/* for profiler */
save_pc();
ENV_YREG = ENV;
#ifdef DEPTH_LIMIT
DEPTH = ENV_YREG[E_DEPTH];
@ -7091,6 +7114,8 @@ Yap_absmi(int inp)
if (ap->OpcodeOfPred != INDEX_OPCODE) {
/* someone was here before we were */
PREG = ap->CodeOfPred;
/* for profiler */
save_pc();
WRITE_UNLOCK(ap->PRWLock);
JMPNext();
}
@ -7106,6 +7131,8 @@ Yap_absmi(int inp)
setregs();
CACHE_A1();
PREG = ap->CodeOfPred;
/* for profiler */
save_pc();
WRITE_UNLOCK(ap->PRWLock);
}
JMPNext();
@ -7117,6 +7144,8 @@ Yap_absmi(int inp)
PredEntry *ap = PredFromDefCode(PREG);
ap = Yap_GetThreadPred(ap);
PREG = ap->CodeOfPred;
/* for profiler */
save_pc();
}
JMPNext();
ENDBOp();
@ -7270,6 +7299,8 @@ Yap_absmi(int inp)
}
PREG = UndefCode->CodeOfPred;
/* for profiler */
save_pc();
CACHE_A1();
JMPNext();
ENDBOp();
@ -7326,6 +7357,8 @@ Yap_absmi(int inp)
pt0 = SpyCode;
P_before_spy = PREG;
PREG = pt0->CodeOfPred;
/* for profiler */
save_pc();
CACHE_A1();
#ifdef LOW_LEVEL_TRACER
if (Yap_do_low_level_trace)
@ -12363,6 +12396,8 @@ Yap_absmi(int inp)
ENV = ENV_YREG;
ENV_YREG -= EnvSizeInCells+3;
PREG = COMMA_CODE;
/* for profiler */
save_pc();
d0 = SREG[1];
goto restart_execute;
@ -12416,6 +12451,8 @@ Yap_absmi(int inp)
CPREG = NEXTOP(PREG, sla);
ALWAYS_LOOKAHEAD(pen->OpcodeOfPred);
PREG = pen->CodeOfPred;
/* for profiler */
save_pc();
#ifdef DEPTH_LIMIT
if (DEPTH <= MkIntTerm(1)) {/* I assume Module==0 is primitives */
if (pen->ModuleOfPred) {
@ -12695,6 +12732,8 @@ Yap_absmi(int inp)
check_stack(NoStackPTExecute, H);
#endif
PREG = pen->CodeOfPred;
/* for profiler */
save_pc();
ALWAYS_LOOKAHEAD(pen->OpcodeOfPred);
ENV_YREG[E_CB] = (CELL)B;
#ifdef LOW_LEVEL_TRACER
@ -12744,6 +12783,9 @@ Yap_absmi(int inp)
}
}
if (ActiveSignals & YAP_TROVF_SIGNAL) {
#if SHADOW_S
S = SREG;
#endif
saveregs_and_ycache();
if(!Yap_growtrail (sizeof(CELL) * 16 * 1024L, FALSE)) {
Yap_Error(OUT_OF_TRAIL_ERROR,TermNil,"YAP failed to reserve %ld bytes in growtrail",sizeof(CELL) * 16 * 1024L);

View File

@ -11,8 +11,12 @@
* File: cdmgr.c *
* comments: Code manager *
* *
* Last rev: $Date: 2005-12-17 03:25:39 $,$Author: vsc $ *
* Last rev: $Date: 2005-12-23 00:20:13 $,$Author: vsc $ *
* $Log: not supported by cvs2svn $
* Revision 1.173 2005/12/17 03:25:39 vsc
* major changes to support online event-based profiling
* improve error discovery and restart on scanner.
*
* Revision 1.172 2005/11/23 03:01:33 vsc
* fix several bugs in save/restore.b
*
@ -552,13 +556,12 @@ Yap_BuildMegaClause(PredEntry *ap)
ClauseCodeToStaticClause(ap->cs.p_code.FirstClause);
/* recover the space spent on the original clauses */
while (TRUE) {
StaticClause *ncl;
StaticClause *ncl, *curcl = cl;
ncl = cl->ClNext;
if (cl->ClFlags & ProfFoundMask)
Yap_InformOfRemoval((CODEADDR)cl);
Yap_InformOfRemoval((CODEADDR)cl);
Yap_FreeCodeSpace((ADDR)cl);
if (cl->ClCode == ap->cs.p_code.LastClause)
if (curcl->ClCode == ap->cs.p_code.LastClause)
break;
cl = ncl;
}
@ -588,8 +591,7 @@ split_megaclause(PredEntry *ap)
while (start) {
StaticClause *cl = start;
start = cl->ClNext;
if (cl->ClFlags & ProfFoundMask)
Yap_InformOfRemoval((CODEADDR)cl);
Yap_InformOfRemoval((CODEADDR)cl);
Yap_FreeCodeSpace((char *)cl);
start = NULL;
}
@ -772,6 +774,7 @@ release_wcls(yamop *cop, OPCODE ecs)
#if DEBUG
Yap_expand_clauses_sz -= (UInt)(NEXTOP((yamop *)NULL,sp)+cop->u.sp.s1*sizeof(yamop *));
#endif
Yap_InformOfRemoval((CODEADDR)cop);
Yap_FreeCodeSpace((char *)cop);
}
}
@ -944,8 +947,7 @@ kill_static_child_indxs(StaticIndex *indx)
kill_static_child_indxs(cl);
cl = next;
}
if (indx->ClFlags & ProfFoundMask)
Yap_InformOfRemoval((CODEADDR)indx);
Yap_InformOfRemoval((CODEADDR)indx);
Yap_FreeCodeSpace((char *)indx);
}
@ -986,8 +988,7 @@ kill_off_lu_block(LogUpdIndex *c, LogUpdIndex *parent, PredEntry *ap)
parent = parent->SiblingIndex;
}
}
if (c->ClFlags & ProfFoundMask)
Yap_InformOfRemoval((CODEADDR)c);
Yap_InformOfRemoval((CODEADDR)c);
Yap_FreeCodeSpace((char *)c);
}
@ -1233,8 +1234,7 @@ retract_all(PredEntry *p, int in_use)
dcl->ClSize = sz;
DeadClauses = dcl;
} else {
if (cl->ClFlags & ProfFoundMask)
Yap_InformOfRemoval((CODEADDR)cl);
Yap_InformOfRemoval((CODEADDR)cl);
Yap_FreeCodeSpace((char *)cl);
}
p->cs.p_code.NOfClauses = 0;
@ -1250,8 +1250,7 @@ retract_all(PredEntry *p, int in_use)
dcl->ClSize = sz;
DeadClauses = dcl;
} else {
if (cl->ClFlags & ProfFoundMask)
Yap_InformOfRemoval((CODEADDR)cl);
Yap_InformOfRemoval((CODEADDR)cl);
Yap_FreeCodeSpace((char *)cl);
}
p->cs.p_code.NOfClauses--;
@ -1973,8 +1972,7 @@ Yap_EraseStaticClause(StaticClause *cl, Term mod) {
dcl->ClSize = sz;
DeadClauses = dcl;
} else {
if (cl->ClFlags & ProfFoundMask)
Yap_InformOfRemoval((CODEADDR)cl);
Yap_InformOfRemoval((CODEADDR)cl);
Yap_FreeCodeSpace((char *)cl);
}
if (ap->cs.p_code.NOfClauses == 0) {
@ -3553,6 +3551,12 @@ ClauseInfoForCode(yamop *codeptr, CODEADDR *startp, CODEADDR *endp) {
case _Nstop:
return NULL;
case _Ystop:
if (pc == YESCODE) {
pp = RepPredProp(Yap_GetPredPropByAtom(AtomTrue,CurrentModule));
*startp = (CODEADDR)YESCODE;
*endp = (CODEADDR)YESCODE; /*+(CELL)(NEXTOP((yamop *)NULL,e));*/
return pp;
}
if (!pp) {
/* must be an index */
PredEntry **pep = (PredEntry **)pc->u.l.l;
@ -3623,12 +3627,7 @@ ClauseInfoForCode(yamop *codeptr, CODEADDR *startp, CODEADDR *endp) {
break;
case _enter_lu_pred:
case _stale_lu_index:
{
LogUpdIndex *icl = ClauseCodeToLogUpdIndex(pc);
*startp = (CODEADDR)icl;
*endp = (CODEADDR)icl+icl->ClSize;
return icl->ClPred;
}
pc = pc->u.Ill.l2;
break;
/* instructions type p */
case _count_call:
@ -3684,16 +3683,17 @@ ClauseInfoForCode(yamop *codeptr, CODEADDR *startp, CODEADDR *endp) {
LogUpdClause *cl = pc->u.EC.ClBase;
*startp = (CODEADDR)cl;
*endp = (CODEADDR)NEXTOP((yamop *)cl,e);
*endp = (CODEADDR)cl+cl->ClSize;
return cl->ClPred;
}
/* instructions type e */
case _unify_idb_term:
case _copy_idb_term:
{
LogUpdClause *cl = (LogUpdClause *)((CELL)pc - (CELL)(((LogUpdClause *)NULL)->ClCode));
LogUpdClause *cl = ClauseCodeToLogUpdClause(pc);
*startp = (CODEADDR)cl;
*endp = (CODEADDR)NEXTOP((yamop *)cl,e);
*endp = (CODEADDR)cl+cl->ClSize;
return cl->ClPred;
}
case _cut:
@ -3812,8 +3812,8 @@ ClauseInfoForCode(yamop *codeptr, CODEADDR *startp, CODEADDR *endp) {
case _p_execute:
clause_code = TRUE;
pp = RepPredProp(Yap_GetPredPropByFunc(FunctorCall, CurrentModule));
*startp = (CODEADDR)&(pp->CodeOfPred);
*endp = (CODEADDR)&(pp->CodeOfPred);
*startp = (CODEADDR)&(pp->OpcodeOfPred);
*endp = (CODEADDR)NEXTOP((yamop *)&(pp->OpcodeOfPred),e);
return pp;
case _fcall:
case _call:
@ -4173,8 +4173,8 @@ ClauseInfoForCode(yamop *codeptr, CODEADDR *startp, CODEADDR *endp) {
case _spy_pred:
case _index_pred:
pp = ((PredEntry *)(Unsigned(pc)-(CELL)(&(((PredEntry *)NULL)->OpcodeOfPred))));
*startp = (CODEADDR)&(pp->CodeOfPred);
*endp = (CODEADDR)&(pp->CodeOfPred);
*startp = (CODEADDR)&(pp->OpcodeOfPred);
*endp = (CODEADDR)NEXTOP((yamop *)&(pp->OpcodeOfPred),e);
return pp;
case _expand_clauses:
/* expansion points may not be found when following the indices tree */
@ -4437,8 +4437,7 @@ p_clean_up_dead_clauses(void)
while (DeadClauses != NULL) {
char *pt = (char *)DeadClauses;
DeadClauses = DeadClauses->NextCl;
if (((DeadClause *)pt)->ClFlags & ProfFoundMask)
Yap_InformOfRemoval((CODEADDR)pt);
Yap_InformOfRemoval((CODEADDR)pt);
Yap_FreeCodeSpace(pt);
}
return(TRUE);

View File

@ -4067,8 +4067,7 @@ complete_lu_erase(LogUpdClause *clau)
}
}
}
if (clau->ClFlags & ProfFoundMask)
Yap_InformOfRemoval((CODEADDR)clau);
Yap_InformOfRemoval((CODEADDR)clau);
Yap_FreeCodeSpace((char *)clau);
}
@ -4188,8 +4187,7 @@ MyEraseClause(DynamicClause *clau)
P = np;
}
} else {
if (clmask & ProfFoundMask)
Yap_InformOfRemoval((CODEADDR)clau);
Yap_InformOfRemoval((CODEADDR)clau);
Yap_FreeCodeSpace((char *)clau);
#ifdef DEBUG
if (ref->NOfRefsTo)

114
C/gprof.c
View File

@ -11,8 +11,11 @@
* File: gprof.c *
* comments: Interrupt Driven Profiler *
* *
* Last rev: $Date: 2005-12-17 03:26:38 $,$Author: vsc $ *
* $Log: not supported by cvs2svn $ *
* Last rev: $Date: 2005-12-23 00:20:13 $,$Author: vsc $ *
* $Log: not supported by cvs2svn $
* Revision 1.1 2005/12/17 03:26:38 vsc
* move event profiler outside from stdpreds.c
* *
*************************************************************************/
#ifdef SCCS
@ -31,7 +34,7 @@ static char SccsId[] = "%W% %G%";
#include <sys/time.h>
#include <ucontext.h>
Int ProfCalls, ProfGCs, ProfHGrows, ProfSGrows, ProfMallocs;
static Int ProfCalls, ProfGCs, ProfHGrows, ProfSGrows, ProfMallocs, ProfOn, ProfOns;
#define TIMER_DEFAULT 100
#define MORE_INFO_FILE 1
@ -98,6 +101,7 @@ Yap_inform_profiler_of_clause(yamop *code_start, yamop *code_end, PredEntry *pe,
static Int order=0;
ProfPreds++;
ProfOn = TRUE;
if (FPreds != NULL) {
Int temp;
order++;
@ -114,6 +118,7 @@ static Int order=0;
#endif
fprintf(FPreds,"\n");
}
ProfOn = FALSE;
}
typedef struct clause_entry {
@ -535,7 +540,7 @@ TreeInsertHelp(rb_red_blk_node* z) {
x=ProfilerRoot->left;
while( x != nil) {
y=x;
if (x->key < z->key) { /* x.key > z.key */
if (x->key > z->key) { /* x.key > z.key */
x=x->left;
} else { /* x,key <= z.key */
x=x->right;
@ -543,7 +548,7 @@ TreeInsertHelp(rb_red_blk_node* z) {
}
z->parent=y;
if ( (y == ProfilerRoot) ||
(y->key < z->key)) { /* y.key > z.key */
(y->key > z->key)) { /* y.key > z.key */
y->left=z;
} else {
y->right=z;
@ -652,14 +657,14 @@ RBExactQuery(yamop* q) {
if (!ProfilerRoot) return NULL;
x=ProfilerRoot->left;
if (x == nil) return(0);
if (x == nil) return NULL;
while(x->key != q) {/*assignemnt*/
if (x->key < q) { /* x->key > q */
if (x->key > q) { /* x->key > q */
x=x->left;
} else {
x=x->right;
}
if ( x == nil) return(0);
if ( x == nil) return NULL;
}
return(x);
}
@ -673,7 +678,7 @@ RBLookup(yamop *entry) {
if (current->key <= entry && current->lim >= entry) {
return current;
}
if (entry < current->key)
if (entry > current->key)
current = current->right;
else
current = current->left;
@ -880,7 +885,7 @@ prof_alrm(int signo, siginfo_t *si, ucontext_t *sc)
void * oldpc= NULL;
#endif
#else
#if __POWERPC__
#if __POWERPC__ || _POWER
void * oldpc=(void *) sc->uc_mcontext->ss.srr0; /* 14= POWER PC */
#else
void *NULL;
@ -893,26 +898,31 @@ prof_alrm(int signo, siginfo_t *si, ucontext_t *sc)
if (Yap_PrologMode & TestMode) {
if (Yap_OffLineProfiler) {
fprintf(FProf,"%p %p\n", (void *) (Yap_PrologMode & TestMode), P);
ProfOn = FALSE;
return;
}
if (Yap_PrologMode & GCMode) {
ProfGCs++;
ProfOn = FALSE;
return;
}
if (Yap_PrologMode & MallocMode) {
ProfMallocs++;
ProfOn = FALSE;
return;
}
if (Yap_PrologMode & GrowHeapMode) {
ProfHGrows++;
ProfOn = FALSE;
return;
}
if (Yap_PrologMode & GrowStackMode) {
ProfSGrows++;
ProfOn = FALSE;
return;
}
@ -936,13 +946,28 @@ prof_alrm(int signo, siginfo_t *si, ucontext_t *sc)
current_p = P;
}
}
if (Yap_OffLineProfiler) {
fprintf(FProf,"0 %p\n", current_p);
if (P < (yamop *)Yap_HeapBase || P > (yamop *)HeapTop) {
#if DEBUG
fprintf(stderr,"Oops: %p, %p\n", oldpc, current_p);
#endif
return;
}
if (Yap_OffLineProfiler) {
ProfOn = FALSE;
return;
}
if (ProfOn) {
ProfOns++;
return;
}
ProfOn = TRUE;
if ((node = RBLookup((yamop *)current_p))) {
node->pcs++;
ProfOn = FALSE;
return;
} else {
PredEntry *pp = NULL;
@ -954,13 +979,28 @@ prof_alrm(int signo, siginfo_t *si, ucontext_t *sc)
fprintf(stderr,"lost %p, %d\n", P, Yap_op_from_opcode(P->opc));
#endif
/* lost profiler event !! */
ProfOn=FALSE;
return;
}
/* add this clause as new node to the tree */
if (start < (CODEADDR)Yap_HeapBase || start > (CODEADDR)HeapTop ||
end < (CODEADDR)Yap_HeapBase || end > (CODEADDR)HeapTop) {
#if DEBUG
fprintf(stderr,"Oops2: %p, %p\n", start, end);
#endif
return;
}
if (pp->ArityOfPE > 100) {
#if DEBUG
fprintf(stderr,"%p:%p(%d)-->%p\n",oldpc,current_p,Yap_op_from_opcode(current_p->opc),pp);
#endif
return;
}
node = RBTreeInsert((yamop *)start, (yamop *)end);
node->pe = pp;
node->pcs = 1;
}
ProfOn = FALSE;
}
@ -971,26 +1011,36 @@ Yap_InformOfRemoval(CODEADDR clau)
UInt count;
PredEntry *pp;
if (FPreds != NULL) {
/* ricardo? */
/* do something */
return;
}
if (!ProfilerRoot) return;
ProfOn = TRUE;
if (!(x = RBExactQuery((yamop *)clau))) {
/* send message */
ProfOn = FALSE;
return;
}
/* just keep within the other profiler for now */
RBDelete(x);
pp = x->pe;
count = x->pcs;
/* fprintf(stderr,"D %p:%p\n",x,pp); */
RBDelete(x);
/* use a single node to represent all deleted clauses */
if (!(node = RBExactQuery((yamop *)pp))) {
node = RBTreeInsert((yamop *)pp, (yamop *)pp);
if (!(node = RBExactQuery((yamop *)(pp->OpcodeOfPred)))) {
node = RBTreeInsert((yamop *)(pp->OpcodeOfPred), NEXTOP((yamop *)(pp->OpcodeOfPred),e));
node->lim = (yamop *)pp;
node->pe = pp;
node->pcs = count;
/* send message */
ProfOn = FALSE;
return;
} else {
node->pcs += count;
}
ProfOn = FALSE;
}
static void
@ -1007,7 +1057,7 @@ reset_tree(void) {
clean_tree(ProfilerRoot);
Yap_FreeCodeSpace((char *)ProfilerNil);
ProfilerNil = ProfilerRoot = NULL;
ProfCalls = ProfGCs = ProfHGrows = ProfSGrows = ProfMallocs = 0L;
ProfCalls = ProfGCs = ProfHGrows = ProfSGrows = ProfMallocs = ProfOns = 0L;
}
static Int profend(void);
@ -1021,6 +1071,10 @@ profnode(void) {
return FALSE;
if (!(node = (rb_red_blk_node *)IntegerOfTerm(t1)))
node = ProfilerRoot;
/*
if (node->key)
fprintf(stderr,"%p: %p,%p,%d,%p(%d),%p,%p\n",node,node->key,node->lim,node->pcs,node->pe,node->pe->ArityOfPE,node->right,node->left);
*/
if (node->left == ProfilerNil) {
tleft = TermNil;
} else {
@ -1051,7 +1105,8 @@ profglobs(void) {
Yap_unify(ARG2,MkIntegerTerm(ProfGCs)) &&
Yap_unify(ARG3,MkIntegerTerm(ProfHGrows)) &&
Yap_unify(ARG4,MkIntegerTerm(ProfSGrows)) &&
Yap_unify(ARG5,MkIntegerTerm(ProfMallocs));
Yap_unify(ARG5,MkIntegerTerm(ProfMallocs)) &&
Yap_unify(ARG6,MkIntegerTerm(ProfOns)) ;
}
static Int profinit(void)
@ -1067,8 +1122,14 @@ static Int profinit(void)
Yap_dump_code_area_for_profiler();
} else {
if (ProfilerRoot)
if (ProfilerRoot)
reset_tree();
while (!(ProfilerRoot = RBTreeCreate())) {
if (!Yap_growheap(FALSE, 0, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, "while initialisating profiler");
return FALSE;
}
}
}
ProfilerOn = -1; /* Inited but not yet started */
return(TRUE);
@ -1116,14 +1177,6 @@ static Int start_profilers(int msec)
if (ProfilerOn!=-1) return (FALSE); /* have to go through profinit */
if (ProfilerRoot)
reset_tree();
while (!(ProfilerRoot = RBTreeCreate())) {
if (!Yap_growheap(FALSE, 0, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, "while initialisating profiler");
return FALSE;
}
}
sa.sa_sigaction=prof_alrm;
sigemptyset(&sa.sa_mask);
sa.sa_flags=SA_SIGINFO;
@ -1151,6 +1204,10 @@ static Int profon0(void) {
return(start_profilers(TIMER_DEFAULT));
}
static Int profison(void) {
return (ProfilerOn > 0);
}
static Int profoff(void) {
if (ProfilerOn>0) {
setitimer(ITIMER_PROF,NULL,NULL);
@ -1242,7 +1299,8 @@ Yap_InitLowProf(void)
Yap_InitCPred("$offline_showprofres", 0, profres0, SafePredFlag);
Yap_InitCPred("$offline_showprofres", 1, profres, SafePredFlag);
Yap_InitCPred("$profnode", 6, profnode, SafePredFlag);
Yap_InitCPred("$profglobs", 5, profglobs, SafePredFlag);
Yap_InitCPred("$profglobs", 6, profglobs, SafePredFlag);
Yap_InitCPred("$profison",0 , profison, SafePredFlag);
Yap_InitCPred("$get_pred_pinfo", 4, getpredinfo, SafePredFlag);
Yap_InitCPred("showprofres", 4, getpredinfo, SafePredFlag);
#endif

View File

@ -11,8 +11,12 @@
* File: index.c *
* comments: Indexing a Prolog predicate *
* *
* Last rev: $Date: 2005-12-17 03:25:39 $,$Author: vsc $ *
* Last rev: $Date: 2005-12-23 00:20:13 $,$Author: vsc $ *
* $Log: not supported by cvs2svn $
* Revision 1.149 2005/12/17 03:25:39 vsc
* major changes to support online event-based profiling
* improve error discovery and restart on scanner.
*
* Revision 1.148 2005/11/24 15:33:52 tiagosoares
* removed some compilation warnings related to the cut-c code
*
@ -622,9 +626,11 @@ sort_group(GroupDef *grp, CELL *top, struct intermediates *cint)
#if USE_SYSTEM_MALLOC
Yap_Error_Size = 2*max*sizeof(CELL);
/* grow stack */
save_machine_regs();
longjmp(cint->CompilerBotch,4);
#else
if (!Yap_growtrail(2*max*CellSize, TRUE)) {
save_machine_regs();
longjmp(cint->CompilerBotch,4);
return;
}
@ -3228,6 +3234,7 @@ emit_switch_space(UInt n, UInt item_size, struct intermediates *cint)
LogUpdIndex *cl = (LogUpdIndex *)Yap_AllocCodeSpace(sz);
if (cl == NULL) {
/* grow stack */
save_machine_regs();
longjmp(cint->CompilerBotch,2);
}
cl->ClFlags = SwitchTableMask|LogUpdMask;
@ -3246,6 +3253,7 @@ emit_switch_space(UInt n, UInt item_size, struct intermediates *cint)
StaticIndex *cl = (StaticIndex *)Yap_AllocCodeSpace(sz);
if (cl == NULL) {
/* grow stack */
save_machine_regs();
longjmp(cint->CompilerBotch,2);
}
cl->ClFlags = SwitchTableMask;
@ -3579,6 +3587,7 @@ suspend_indexing(ClauseDef *min, ClauseDef *max, PredEntry *ap, struct intermedi
Yap_expand_clauses_sz += sz;
#endif
if ((ncode = (yamop *)Yap_AllocCodeSpace(sz)) == NULL) {
save_machine_regs();
longjmp(cint->CompilerBotch, 2);
}
#ifdef LOW_PROF
@ -4140,6 +4149,7 @@ copy_clauses(ClauseDef *max0, ClauseDef *min0, CELL *top, struct intermediates *
if ((char *)top + sz >= Yap_TrailTop-4096) {
Yap_Error_Size = sz;
/* grow stack */
save_machine_regs();
longjmp(cint->CompilerBotch,4);
}
memcpy((void *)top, (void *)min0, sz);
@ -4331,6 +4341,7 @@ compile_index(struct intermediates *cint)
/* tell how much space we need */
Yap_Error_Size += NClauses*sizeof(ClauseDef);
/* grow stack */
save_machine_regs();
longjmp(cint->CompilerBotch,3);
}
cint->freep = (char *)(cls+NClauses);
@ -4375,6 +4386,7 @@ Yap_PredIsIndexable(PredEntry *ap, UInt NSlots)
return FAILCODE;
}
} else if (setjres != 0) {
restore_machine_regs();
recover_from_failed_susp_on_cls(&cint, 0);
if (!Yap_growheap(FALSE, Yap_Error_Size, NULL)) {
Yap_Error(OUT_OF_HEAP_ERROR, TermNil, Yap_ErrorMessage);
@ -4425,7 +4437,8 @@ static istack_entry *
push_stack(istack_entry *sp, Int arg, Term Tag, Term extra, struct intermediates *cint)
{
if (sp+1 > (istack_entry *)Yap_TrailTop) {
longjmp(cint->CompilerBotch,4);
save_machine_regs();
longjmp(cint->CompilerBotch,4);
}
sp->pos = arg;
sp->val = Tag;
@ -5207,6 +5220,7 @@ expand_index(struct intermediates *cint) {
/* tell how much space we need (worst case) */
Yap_Error_Size += 2*NClauses*sizeof(ClauseDef);
/* grow stack */
save_machine_regs();
longjmp(cint->CompilerBotch,3);
}
if (ap->PredFlags & LogUpdatePredFlag) {
@ -5219,6 +5233,7 @@ expand_index(struct intermediates *cint) {
if (cls+2*NClauses > (ClauseDef *)(ASP-4096)) {
/* tell how much space we need (worst case) */
Yap_Error_Size += 2*NClauses*sizeof(ClauseDef);
save_machine_regs();
longjmp(cint->CompilerBotch,3);
}
if (ap->PredFlags & LogUpdatePredFlag) {
@ -5463,7 +5478,8 @@ static path_stack_entry *
push_path(path_stack_entry *sp, yamop **pipc, ClauseDef *clp, struct intermediates *cint)
{
if (sp+1 > (path_stack_entry *)Yap_TrailTop) {
longjmp(cint->CompilerBotch,4);
save_machine_regs();
longjmp(cint->CompilerBotch,4);
}
sp->flag = pc_entry;
sp->u.pce.pi_pc = pipc;
@ -5627,6 +5643,7 @@ replace_index_block(ClauseUnion *parent_block, yamop *cod, yamop *ncod, PredEntr
c->ParentIndex = ncl;
c = c->SiblingIndex;
}
Yap_InformOfRemoval((CODEADDR)cl);
Yap_FreeCodeSpace((char *)cl);
} else {
StaticIndex
@ -5643,6 +5660,7 @@ replace_index_block(ClauseUnion *parent_block, yamop *cod, yamop *ncod, PredEntr
}
c->SiblingIndex = ncl;
}
Yap_InformOfRemoval((CODEADDR)cl);
Yap_FreeCodeSpace((char *)cl);
}
}
@ -6100,7 +6118,7 @@ cp_lu_trychain(yamop *codep, yamop *ocodep, yamop *ostart, int flag, PredEntry *
}
codep->opc = Yap_opcode(_Ystop);
/* this must be updated if we are copying to different place */
codep->u.l.l = ostart;
codep->u.l.l = nblk->ClCode;
return codep;
}
@ -6412,7 +6430,7 @@ insertz_in_lu_block(LogUpdIndex *blk, PredEntry *ap, yamop *code)
where = NEXTOP(where,ld);
begin->u.Ill.l2 = where;
where->opc = Yap_opcode(_Ystop);
where->u.l.l = begin;
where->u.l.l = blk->ClCode;
begin->u.Ill.s++;
tgl->ClRefCount++;
return blk->ClCode;
@ -6524,6 +6542,7 @@ expanda_block(path_stack_entry *sp, PredEntry *ap, ClauseDef *cls, int group1, y
inserta_in_lu_block((LogUpdIndex *)sp->u.cle.block, ap, cls->Code);
if (new_code == NULL) {
recover_from_failed_susp_on_cls(cint, 0);
save_machine_regs();
longjmp(cint->CompilerBotch,2);
}
*sp->u.cle.entry_code = new_code;
@ -6549,6 +6568,7 @@ expandz_block(path_stack_entry *sp, PredEntry *ap, ClauseDef *cls, int group1, y
insertz_in_lu_block((LogUpdIndex *)sp->u.cle.block, ap, cls->Code);
if (new_code == NULL) {
recover_from_failed_susp_on_cls(cint, 0);
save_machine_regs();
longjmp(cint->CompilerBotch,2);
}
*sp->u.cle.entry_code =

View File

@ -500,7 +500,8 @@ Yap_InitCPred(char *Name, unsigned long int Arity, CPredicate code, int flags)
return;
}
} else {
cl->ClFlags = 0;
cl->ClFlags = StaticMask;
cl->ClNext = NULL;
cl->ClSize = sz;
cl->usc.ClPred = pe;
p_code = cl->ClCode;
@ -561,9 +562,10 @@ Yap_InitCmpPred(char *Name, unsigned long int Arity, CmpPredicate cmp_code, int
return;
}
} else {
cl->ClFlags = StaticMask;
cl->ClNext = NULL;
cl->ClSize = sz;
cl->usc.ClPred = pe;
cl->ClFlags = 0;
p_code = cl->ClCode;
break;
}
@ -608,7 +610,8 @@ Yap_InitAsmPred(char *Name, unsigned long int Arity, int code, CPredicate def,
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"No Heap Space in InitAsmPred");
return;
}
cl->ClFlags = 0;
cl->ClFlags = StaticMask;
cl->ClNext = NULL;
cl->ClSize = (CELL)NEXTOP(NEXTOP(NEXTOP(((yamop *)p_code),sla),e),e);
cl->usc.ClPred = pe;
p_code = cl->ClCode;
@ -744,7 +747,8 @@ Yap_InitCPredBack(char *Name, unsigned long int Arity,
Yap_Error(OUT_OF_HEAP_ERROR,TermNil,"No Heap Space in InitCPredBack");
return;
}
cl->ClFlags = 0L;
cl->ClFlags = StaticMask;
cl->ClNext = NULL;
#ifdef CUT_C
cl->ClSize =
(CELL)NEXTOP(NEXTOP(NEXTOP(NEXTOP(code,lds),lds),lds),e);

View File

@ -1244,6 +1244,7 @@ InteractSIGINT(int ch) {
} else {
Yap_Error(PURE_ABORT, TermNil, "");
/* in case someone mangles the P register */
save_machine_regs();
#if _MSC_VER || defined(__MINGW32__)
/* don't even think about trying this */
#else

View File

@ -10,7 +10,7 @@
* File: Regs.h *
* mods: *
* comments: YAP abstract machine registers *
* version: $Id: Regs.h,v 1.31 2005-11-18 18:50:34 tiagosoares Exp $ *
* version: $Id: Regs.h,v 1.32 2005-12-23 00:20:14 vsc Exp $ *
*************************************************************************/
@ -37,7 +37,7 @@
#undef PUSH_X
#endif
#ifdef _POWER
#if defined(_POWER) || defined(__POWERPC__)
#undef PUSH_REGS
#undef PUSH_X
#endif
@ -513,7 +513,7 @@ EXTERN inline void restore_TR(void) {
TR = Yap_REGS.TR_;
}
#elif defined(__GNUC__) && defined(_POWER)
#elif defined(__GNUC__) && (defined(_POWER) || defined(__POWERPC__))
/*

View File

@ -18,7 +18,7 @@
* Last rev: December 90 *
* mods: *
* comments: Original Tag Scheme for machines with 32 bits adresses *
* version: $Id: Tags_32Ops.h,v 1.1 2005-05-27 22:27:06 rslopes Exp $ *
* version: $Id: Tags_32Ops.h,v 1.2 2005-12-23 00:20:14 vsc Exp $ *
*************************************************************************/
/*
@ -78,7 +78,7 @@ are now 1 in compound terms and structures.
This allows optimisation of switch_list
*/
#if defined(i386) || defined(sparc) || defined(_POWER) || defined(__sparc)
#if defined(i386) || defined(sparc) || defined(_POWER) || defined(__POWERPC__) || defined(__sparc)
#define UNIQUE_TAG_FOR_PAIRS 1
#endif

View File

@ -10,7 +10,7 @@
* File: Yap.h.m4 *
* mods: *
* comments: main header file for YAP *
* version: $Id: Yap.h,v 1.10 2005-12-17 03:25:39 vsc Exp $ *
* version: $Id: Yap.h,v 1.11 2005-12-23 00:20:14 vsc Exp $ *
*************************************************************************/
#include "config.h"
@ -642,7 +642,7 @@ typedef enum
if you place things in the lower addresses (power to the libc people).
*/
#if (defined(_AIX) || defined(_WIN32) || defined(__APPLE__) || defined(sparc) || defined(__sparc) || defined(mips) || defined(__FreeBSD__) || defined(__POWERPC__) || defined(__linux__) || defined(IN_SECOND_QUADRANT) || defined(__CYGWIN__))
#if (defined(_AIX) || defined(_WIN32) || defined(__APPLE__) || defined(sparc) || defined(__sparc) || defined(mips) || defined(__FreeBSD__) || defined(_POWER) || defined(__POWERPC__) || defined(__linux__) || defined(IN_SECOND_QUADRANT) || defined(__CYGWIN__))
#define USE_LOW32_TAGS 1
#endif

View File

@ -60,7 +60,7 @@ static char SccsId[] = "%W% %G%";
#define USE_PREFETCH 1
#endif
#if defined(_POWER)
#if defined(_POWER) || defined(__POWERPC__)
#define SHADOW_P 1
#define SHADOW_REGS 1
#define USE_PREFETCH 1
@ -553,7 +553,7 @@ typedef CELL label;
#endif /* PRECOMPUTE_REGADDRESS */
/* The Unification Stack is the Auxiliary stack */
/* The Unification Stack is the Auxiliary stack */
#define SP0 ((CELL *)AuxTop)
#define SP AuxSp

View File

@ -16,6 +16,10 @@
<h2>Yap-5.1.0:</h2>
<ul>
<li> FIXED: handle assert/retracts and gprof overhead right. </li>
<li> FIXED: indexing code was not setting up properly registers on longjmps. </li>
<li> FIXED: use RISC architecture on MacOsX (__POWERPC__ + _POWER). </li>
<li> FIXED: init system predicates should generate full static clause. </li>
<li> NEW: tabling does not conflit with depth limit (Trevor Walker). </li>
<li> NEW: make scanner restartable on seekable files (Nuno Fonseca). </li>
<li> NEW: improve error discovery within scanner (Jude Shavlik). </li>

View File

@ -67,23 +67,40 @@ showprofres :-
'$proftype'(offline),
'$offline_showprofres'.
showprofres :-
'$profglobs'(Tot,GCs,HGrows,SGrows,Mallocs),
('$profison' -> profoff, Stop = true ; Stop = false),
'$profglobs'(Tot,GCs,HGrows,SGrows,Mallocs,ProfOns),
% root node has no useful info.
'$get_all_profinfo'(0,[],ProfInfo0),
sort(ProfInfo0,ProfInfo),
'$get_all_profinfo'(0,[],ProfInfo0,0,TotCode),
msort(ProfInfo0,ProfInfo),
'$get_ppreds'(ProfInfo,Preds0),
'$add_extras_prof'(GCs, HGrows, SGrows, Mallocs, Preds0, PredsI),
keysort(PredsI,Preds),
'$sum_alls'(Preds,0,Tot0),
Accounted is -Tot0,
format(user_error,'~d ticks, ~d accounted for~n',[Tot,Accounted]),
'$display_preds'(Preds, Tot, 0, 1).
(ProfOns == 0 ->
format(user_error,'~d ticks, ~d accounted for~n',[Tot,Accounted])
;
format(user_error,'~d ticks, ~d accounted for (~d overhead)~n',[Tot,Accounted,ProfOns])
),
'$display_preds'(Preds, Tot, 0, 1),
(Stop = true -> profon ; true).
'$get_all_profinfo'([],L,L) :- !.
'$get_all_profinfo'(Node,L0,Lf) :-
/*
'$check_duplicates'([]).
'$check_duplicates'([A,A|ProfInfo]) :- !,
write(A),nl,
'$check_duplicates'(ProfInfo).
'$check_duplicates'([_|ProfInfo]) :-
'$check_duplicates'(ProfInfo).
*/
'$get_all_profinfo'([],L,L,Tot,Tot) :- !.
'$get_all_profinfo'(Node,L0,Lf,Tot0,Totf) :-
'$profnode'(Node,Clause,PredId,Count,Left,Right),
'$get_all_profinfo'(Left,L0,Li),
'$get_all_profinfo'(Right,[gprof(PredId,Clause,Count)|Li],Lf).
Tot1 is Tot0+Count,
'$get_all_profinfo'(Left,L0,Li,Tot1,Tot2),
'$get_all_profinfo'(Right,[gprof(PredId,Clause,Count)|Li],Lf,Tot2,Totf).
'$get_ppreds'([],[]).
'$get_ppreds'([gprof(0,_,0)|Cls],Ps) :- !,