From bf80a3a11def6ba68d8f248b389ba84e4e32ced3 Mon Sep 17 00:00:00 2001 From: Richard Kistruck Date: Thu, 20 Aug 2009 17:44:16 +0100 Subject: [PATCH] Mps br/padding: new pooltraceendmethod: do end-of-trace work Tracer calls PoolTraceEnd() when the trace is TraceFINISHED. AbstractPoolClass uses PoolTrivTraceEnd -- a NOOP. [mpm.h, mpmst.h, mpmtypes.h, pool.c, poolabs.c] AMC overrides with AMCTraceEnd, to emit diagnostic on how well the trace went! [poolamc.c] Copied from Perforce Change: 168478 ServerID: perforce.ravenbrook.com --- mps/code/diag.c | 1 + mps/code/mpm.h | 2 ++ mps/code/mpmst.h | 1 + mps/code/mpmtypes.h | 1 + mps/code/pool.c | 17 +++++++++++++++++ mps/code/poolabs.c | 8 ++++++++ mps/code/poolamc.c | 19 +++++++++++++++++++ mps/code/trace.c | 8 ++++++++ 8 files changed, 57 insertions(+) diff --git a/mps/code/diag.c b/mps/code/diag.c index 45d473ddf09..9ee4deb0ada 100644 --- a/mps/code/diag.c +++ b/mps/code/diag.c @@ -46,6 +46,7 @@ struct RuleStruct RulesGlobal[] = { { "+", "TraceStart", "*", " PoolSum-" }, { "+", "TraceStart", "*", "MutatorSize " }, /* fillMutatorSize, emptyMutatorSize, fillInternalSize, emptyInternalSize */ { "+", "TraceStart", "*", " segs" }, /* amcGen 0..N segs 3, totalSize 49152, newSize 0 */ + { "+", "AMCTraceEnd", "*", "*" }, /* ----v---- always on please (RHSK) ----v---- */ { "+", "traceSetSignalEmergency", "*", "*" }, { NULL, "", "", "" } diff --git a/mps/code/mpm.h b/mps/code/mpm.h index 1ca74e6ffd7..b4189afadcd 100644 --- a/mps/code/mpm.h +++ b/mps/code/mpm.h @@ -211,6 +211,7 @@ extern Res (PoolFix)(Pool pool, ScanState ss, Seg seg, Addr *refIO); ((*(pool)->fix)(pool, ss, seg, refIO)) extern void PoolFixEmergency(Pool pool, ScanState ss, Seg seg, Addr *refIO); extern void PoolReclaim(Pool pool, Trace trace, Seg seg); +extern void PoolTraceEnd(Pool pool, Trace trace); extern void PoolWalk(Pool pool, Seg seg, FormattedObjectsStepMethod f, void *v, unsigned long s); extern void PoolFreeWalk(Pool pool, FreeBlockStepMethod f, void *p); @@ -250,6 +251,7 @@ extern void PoolTrivBlacken(Pool pool, TraceSet traceSet, Seg seg); extern Res PoolNoScan(Bool *totalReturn, ScanState ss, Pool pool, Seg seg); extern Res PoolNoFix(Pool pool, ScanState ss, Seg seg, Ref *refIO); extern void PoolNoReclaim(Pool pool, Trace trace, Seg seg); +extern void PoolTrivTraceEnd(Pool pool, Trace trace); extern void PoolNoRampBegin(Pool pool, Buffer buf, Bool collectAll); extern void PoolTrivRampBegin(Pool pool, Buffer buf, Bool collectAll); extern void PoolNoRampEnd(Pool pool, Buffer buf); diff --git a/mps/code/mpmst.h b/mps/code/mpmst.h index e0a76f9bf0c..eeafab47fdc 100644 --- a/mps/code/mpmst.h +++ b/mps/code/mpmst.h @@ -66,6 +66,7 @@ typedef struct PoolClassStruct { PoolFixMethod fix; /* referent reachable during tracing */ PoolFixEmergencyMethod fixEmergency; /* as fix, no failure allowed */ PoolReclaimMethod reclaim; /* reclaim dead objects after tracing */ + PoolTraceEndMethod traceEnd; /* do end-of-trace work */ PoolRampBeginMethod rampBegin;/* begin a ramp pattern */ PoolRampEndMethod rampEnd; /* end a ramp pattern */ PoolFramePushMethod framePush; /* push an allocation frame */ diff --git a/mps/code/mpmtypes.h b/mps/code/mpmtypes.h index bd232110349..fd27f8c2a80 100644 --- a/mps/code/mpmtypes.h +++ b/mps/code/mpmtypes.h @@ -198,6 +198,7 @@ typedef Res (*PoolFixMethod)(Pool pool, ScanState ss, Seg seg, typedef Res (*PoolFixEmergencyMethod)(Pool pool, ScanState ss, Seg seg, Ref *refIO); typedef void (*PoolReclaimMethod)(Pool pool, Trace trace, Seg seg); +typedef void (*PoolTraceEndMethod)(Pool pool, Trace trace); typedef void (*PoolRampBeginMethod)(Pool pool, Buffer buf, Bool collectAll); typedef void (*PoolRampEndMethod)(Pool pool, Buffer buf); typedef Res (*PoolFramePushMethod)(AllocFrame *frameReturn, diff --git a/mps/code/pool.c b/mps/code/pool.c index 05045b3f309..e92106128c3 100644 --- a/mps/code/pool.c +++ b/mps/code/pool.c @@ -461,6 +461,23 @@ void PoolReclaim(Pool pool, Trace trace, Seg seg) } +/* PoolTraceEnd -- do end-of-trace work + * + * This method is for a pool class to do final end-of-trace work, + * after all reclaiming is complete. For example, emitting + * diagnostics about what happened during the trace. + */ + +void PoolTraceEnd(Pool pool, Trace trace) +{ + AVERT(Pool, pool); + AVERT(Trace, trace); + AVER(pool->arena == trace->arena); + + (*pool->class->traceEnd)(pool, trace); +} + + /* PoolWalk -- walk objects in this segment */ void PoolWalk(Pool pool, Seg seg, FormattedObjectsStepMethod f, diff --git a/mps/code/poolabs.c b/mps/code/poolabs.c index 3e52dc63c14..324975cb7c0 100644 --- a/mps/code/poolabs.c +++ b/mps/code/poolabs.c @@ -136,6 +136,7 @@ DEFINE_CLASS(AbstractPoolClass, class) class->fix = PoolNoFix; class->fixEmergency = PoolNoFix; class->reclaim = PoolNoReclaim; + class->traceEnd = PoolTrivTraceEnd; class->rampBegin = PoolNoRampBegin; class->rampEnd = PoolNoRampEnd; class->framePush = PoolNoFramePush; @@ -529,6 +530,13 @@ void PoolNoReclaim(Pool pool, Trace trace, Seg seg) NOTREACHED; } +void PoolTrivTraceEnd(Pool pool, Trace trace) +{ + AVERT(Pool, pool); + AVERT(Trace, trace); + NOOP; +} + void PoolNoRampBegin(Pool pool, Buffer buf, Bool collectAll) { diff --git a/mps/code/poolamc.c b/mps/code/poolamc.c index 02984e08c12..6c3a3da4d99 100644 --- a/mps/code/poolamc.c +++ b/mps/code/poolamc.c @@ -2232,6 +2232,24 @@ static void AMCReclaim(Pool pool, Trace trace, Seg seg) } +/* AMCTraceEnd -- emit end-of-trace diagnostics + * + */ +static void AMCTraceEnd(Pool pool, Trace trace) +{ + AMC amc; + + AVERT(Pool, pool); + amc = Pool2AMC(pool); + AVERT(AMC, amc); + AVERT(Trace, trace); + + DIAG_SINGLEF(( "AMCTraceEnd", + " pool: $P\n", pool, + NULL )); +} + + /* AMCWalk -- Apply function to (black) objects in segment */ static void AMCWalk(Pool pool, Seg seg, FormattedObjectsStepMethod f, @@ -2424,6 +2442,7 @@ DEFINE_POOL_CLASS(AMCPoolClass, this) this->fix = AMCFix; this->fixEmergency = AMCFixEmergency; this->reclaim = AMCReclaim; + this->traceEnd = AMCTraceEnd; this->rampBegin = AMCRampBegin; this->rampEnd = AMCRampEnd; this->walk = AMCWalk; diff --git a/mps/code/trace.c b/mps/code/trace.c index 1082eaefe78..ff13b6180a9 100644 --- a/mps/code/trace.c +++ b/mps/code/trace.c @@ -770,6 +770,7 @@ static void traceReclaim(Trace trace) { Arena arena; Seg seg; + Ring node, nextNode; AVER(trace->state == TraceRECLAIM); @@ -805,6 +806,13 @@ static void traceReclaim(Trace trace) } trace->state = TraceFINISHED; + + /* Call each pool's TraceEnd method -- do end-of-trace work */ + RING_FOR(node, &ArenaGlobals(arena)->poolRing, nextNode) { + Pool pool = RING_ELT(Pool, arenaRing, node); + PoolTraceEnd(pool, trace); + } + TracePostMessage(trace); /* trace end */ /* Immediately pre-allocate messages for next time; failure is okay */ (void)TraceIdMessagesCreate(arena, trace->ti);