mirror of
git://git.sv.gnu.org/emacs.git
synced 2026-03-26 08:41:47 -07:00
Using mustbea to reduce boilerplate in client arenas, fotest, and the amc pool.
Copied from Perforce Change: 190906 ServerID: perforce.ravenbrook.com
This commit is contained in:
parent
e99abe1ee2
commit
30d1c5fa63
4 changed files with 37 additions and 107 deletions
|
|
@ -34,9 +34,6 @@ typedef struct ClientArenaStruct {
|
|||
} ClientArenaStruct;
|
||||
typedef struct ClientArenaStruct *ClientArena;
|
||||
|
||||
#define Arena2ClientArena(arena) PARENT(ClientArenaStruct, arenaStruct, arena)
|
||||
#define ClientArena2Arena(clArena) (&(clArena)->arenaStruct)
|
||||
|
||||
|
||||
/* CLChunk -- chunk structure */
|
||||
|
||||
|
|
@ -83,11 +80,8 @@ static Bool ClientChunkCheck(ClientChunk clChunk)
|
|||
ATTRIBUTE_UNUSED
|
||||
static Bool ClientArenaCheck(ClientArena clientArena)
|
||||
{
|
||||
Arena arena;
|
||||
Arena arena = MustBeA(AbstractArena, clientArena);
|
||||
|
||||
CHECKS(ClientArena, clientArena);
|
||||
arena = ClientArena2Arena(clientArena);
|
||||
CHECKD(Arena, arena);
|
||||
/* See <code/arena.c#.reserved.check> */
|
||||
CHECKL(arena->committed <= arena->reserved);
|
||||
CHECKL(arena->spareCommitted == 0);
|
||||
|
|
@ -101,7 +95,7 @@ static Bool ClientArenaCheck(ClientArena clientArena)
|
|||
static Res clientChunkCreate(Chunk *chunkReturn, ClientArena clientArena,
|
||||
Addr base, Addr limit)
|
||||
{
|
||||
Arena arena;
|
||||
Arena arena = MustBeA(AbstractArena, clientArena);
|
||||
ClientChunk clChunk;
|
||||
Chunk chunk;
|
||||
Addr alignedBase;
|
||||
|
|
@ -111,8 +105,6 @@ static Res clientChunkCreate(Chunk *chunkReturn, ClientArena clientArena,
|
|||
void *p;
|
||||
|
||||
AVER(chunkReturn != NULL);
|
||||
AVERT(ClientArena, clientArena);
|
||||
arena = ClientArena2Arena(clientArena);
|
||||
AVER(base != (Addr)0);
|
||||
AVER(limit != (Addr)0);
|
||||
AVER(limit > base);
|
||||
|
|
@ -290,7 +282,7 @@ static Res ClientArenaCreate(Arena *arenaReturn, ArgList args)
|
|||
if (chunkBase > limit)
|
||||
return ResMEMORY;
|
||||
|
||||
arena = ClientArena2Arena(clientArena);
|
||||
arena = CouldBeA(AbstractArena, clientArena);
|
||||
/* <code/arena.c#init.caller> */
|
||||
res = SUPERCLASS(Arena, ClientArena)->init(arena, grainSize, args);
|
||||
if (res != ResOK)
|
||||
|
|
@ -330,10 +322,7 @@ failSuperInit:
|
|||
|
||||
static void ClientArenaDestroy(Arena arena)
|
||||
{
|
||||
ClientArena clientArena;
|
||||
|
||||
clientArena = Arena2ClientArena(arena);
|
||||
AVERT(ClientArena, clientArena);
|
||||
ClientArena clientArena = MustBeA(ClientArena, arena);
|
||||
|
||||
/* Destroy all chunks, including the primary. See
|
||||
* <design/arena/#chunk.delete> */
|
||||
|
|
@ -355,19 +344,13 @@ static void ClientArenaDestroy(Arena arena)
|
|||
|
||||
static Res ClientArenaExtend(Arena arena, Addr base, Size size)
|
||||
{
|
||||
ClientArena clientArena;
|
||||
ClientArena clientArena = MustBeA(ClientArena, arena);
|
||||
Chunk chunk;
|
||||
Res res;
|
||||
Addr limit;
|
||||
|
||||
AVERT(Arena, arena);
|
||||
AVER(base != (Addr)0);
|
||||
AVER(size > 0);
|
||||
limit = AddrAdd(base, size);
|
||||
|
||||
clientArena = Arena2ClientArena(arena);
|
||||
res = clientChunkCreate(&chunk, clientArena, base, limit);
|
||||
return res;
|
||||
return clientChunkCreate(&chunk, clientArena, base, AddrAdd(base, size));
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -407,7 +390,6 @@ static void ClientArenaFree(Addr base, Size size, Pool pool)
|
|||
Arena arena;
|
||||
Chunk chunk = NULL; /* suppress "may be used uninitialized" */
|
||||
Size pages;
|
||||
ClientArena clientArena;
|
||||
Index pi, baseIndex, limitIndex;
|
||||
Bool foundChunk;
|
||||
ClientChunk clChunk;
|
||||
|
|
@ -416,9 +398,7 @@ static void ClientArenaFree(Addr base, Size size, Pool pool)
|
|||
AVER(size > (Size)0);
|
||||
AVERT(Pool, pool);
|
||||
arena = PoolArena(pool);
|
||||
AVERT(Arena, arena);
|
||||
clientArena = Arena2ClientArena(arena);
|
||||
AVERT(ClientArena, clientArena);
|
||||
AVERC(ClientArena, arena);
|
||||
AVER(SizeIsAligned(size, ChunkPageSize(arena->primary)));
|
||||
AVER(AddrIsAligned(base, ChunkPageSize(arena->primary)));
|
||||
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ static mps_res_t make(mps_addr_t *p, mps_ap_t ap, size_t size)
|
|||
|
||||
static void set_oom(Land land, int oom)
|
||||
{
|
||||
CBS cbs = PARENT(CBSStruct, landStruct, land);
|
||||
CBS cbs = MustBeA(CBS, land);
|
||||
SetClassOfPool(cbs->blockPool, oom ? CLASS(OOMPool) : PoolClassMFS());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -74,6 +74,7 @@ typedef unsigned FrameState; /* <design/alloc-frame/> */
|
|||
typedef struct mps_fmt_s *Format; /* design.mps.format */
|
||||
typedef struct LockStruct *Lock; /* <code/lock.c>* */
|
||||
typedef struct mps_pool_s *Pool; /* <design/pool/> */
|
||||
typedef Pool AbstractPool;
|
||||
typedef struct mps_pool_class_s *PoolClass; /* <code/poolclas.c> */
|
||||
typedef struct TraceStruct *Trace; /* <design/trace/> */
|
||||
typedef struct ScanStateStruct *ScanState; /* <design/trace/> */
|
||||
|
|
@ -89,6 +90,7 @@ typedef struct LocusPrefStruct *LocusPref; /* <design/locus/>, <code/locus.c> */
|
|||
typedef int LocusPrefKind; /* <design/locus/>, <code/locus.c> */
|
||||
typedef struct mps_arena_class_s *ArenaClass; /* <design/arena/> */
|
||||
typedef struct mps_arena_s *Arena; /* <design/arena/> */
|
||||
typedef Arena AbstractArena;
|
||||
typedef struct GlobalsStruct *Globals; /* <design/arena/> */
|
||||
typedef struct VMStruct *VM; /* <code/vm.c>* */
|
||||
typedef struct RootStruct *Root; /* <code/root.c> */
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ SRCID(poolamc, "$Id$");
|
|||
/* AMC typedef */
|
||||
/* FIXME: Inconsistent naming of AMCPool class and AMC types. */
|
||||
typedef struct AMCStruct *AMC, *AMCPool, *AMCZPool;
|
||||
#define AMCZPoolCheck AMCCheck
|
||||
|
||||
/* amcGen typedef */
|
||||
typedef struct amcGenStruct *amcGen;
|
||||
|
|
@ -49,7 +50,7 @@ typedef struct amcGenStruct {
|
|||
Sig sig; /* <code/misc.h#sig> */
|
||||
} amcGenStruct;
|
||||
|
||||
#define amcGenAMC(amcgen) PoolAMC((amcgen)->pgen.pool)
|
||||
#define amcGenAMC(amcgen) MustBeA(AMCZPool, (amcgen)->pgen.pool)
|
||||
#define amcGenPool(amcgen) ((amcgen)->pgen.pool)
|
||||
|
||||
#define amcGenNr(amcgen) ((amcgen)->pgen.nr)
|
||||
|
|
@ -406,9 +407,6 @@ typedef struct AMCStruct { /* <design/poolamc/#struct> */
|
|||
Sig sig; /* <design/pool/#outer-structure.sig> */
|
||||
} AMCStruct;
|
||||
|
||||
#define PoolAMC(pool) PARENT(AMCStruct, poolStruct, (pool))
|
||||
#define AMCPool(amc) (&(amc)->poolStruct)
|
||||
|
||||
|
||||
/* amcGenCheck -- check consistency of a generation structure */
|
||||
|
||||
|
|
@ -547,14 +545,13 @@ DEFINE_CLASS(Buffer, amcBuf, class)
|
|||
|
||||
static Res amcGenCreate(amcGen *genReturn, AMC amc, GenDesc gen)
|
||||
{
|
||||
Pool pool = MustBeA(AbstractPool, amc);
|
||||
Arena arena;
|
||||
Buffer buffer;
|
||||
Pool pool;
|
||||
amcGen amcgen;
|
||||
Res res;
|
||||
void *p;
|
||||
|
||||
pool = AMCPool(amc);
|
||||
arena = pool->arena;
|
||||
|
||||
res = ControlAlloc(&p, arena, sizeof(amcGenStruct));
|
||||
|
|
@ -660,7 +657,7 @@ static Res amcSegCreateNailboard(Seg seg, Pool pool)
|
|||
|
||||
static Bool amcPinnedInterior(AMC amc, Nailboard board, Addr base, Addr limit)
|
||||
{
|
||||
Size headerSize = AMCPool(amc)->format->headerSize;
|
||||
Size headerSize = MustBeA(AbstractPool, amc)->format->headerSize;
|
||||
return !NailboardIsResRange(board, AddrSub(base, headerSize),
|
||||
AddrSub(limit, headerSize));
|
||||
}
|
||||
|
|
@ -845,14 +842,10 @@ static Res AMCZInit(Pool pool, Arena arena, PoolClass class, ArgList args)
|
|||
*/
|
||||
static void AMCFinish(Pool pool)
|
||||
{
|
||||
AMC amc;
|
||||
AMC amc = MustBeA(AMCZPool, pool);
|
||||
Ring ring;
|
||||
Ring node, nextNode;
|
||||
|
||||
AVERT(Pool, pool);
|
||||
amc = PoolAMC(pool);
|
||||
AVERT(AMC, amc);
|
||||
|
||||
EVENT1(AMCFinish, amc);
|
||||
|
||||
/* @@@@ Make sure that segments aren't buffered by forwarding */
|
||||
|
|
@ -902,7 +895,7 @@ static Res AMCBufferFill(Addr *baseReturn, Addr *limitReturn,
|
|||
Pool pool, Buffer buffer, Size size)
|
||||
{
|
||||
Seg seg;
|
||||
AMC amc;
|
||||
AMC amc = MustBeA(AMCZPool, pool);
|
||||
Res res;
|
||||
Addr base, limit;
|
||||
Arena arena;
|
||||
|
|
@ -911,9 +904,6 @@ static Res AMCBufferFill(Addr *baseReturn, Addr *limitReturn,
|
|||
PoolGen pgen;
|
||||
amcBuf amcbuf = MustBeA(amcBuf, buffer);
|
||||
|
||||
AVERT(Pool, pool);
|
||||
amc = PoolAMC(pool);
|
||||
AVERT(AMC, amc);
|
||||
AVER(baseReturn != NULL);
|
||||
AVER(limitReturn != NULL);
|
||||
AVERT(Buffer, buffer);
|
||||
|
|
@ -995,14 +985,11 @@ static Res AMCBufferFill(Addr *baseReturn, Addr *limitReturn,
|
|||
static void AMCBufferEmpty(Pool pool, Buffer buffer,
|
||||
Addr init, Addr limit)
|
||||
{
|
||||
AMC amc;
|
||||
AMC amc = MustBeA(AMCZPool, pool);
|
||||
Size size;
|
||||
Arena arena;
|
||||
Seg seg;
|
||||
|
||||
AVERT(Pool, pool);
|
||||
amc = PoolAMC(pool);
|
||||
AVERT(AMC, amc);
|
||||
AVERT(Buffer, buffer);
|
||||
AVER(BufferIsReady(buffer));
|
||||
seg = BufferSeg(buffer);
|
||||
|
|
@ -1037,11 +1024,8 @@ static void AMCBufferEmpty(Pool pool, Buffer buffer,
|
|||
|
||||
static void AMCRampBegin(Pool pool, Buffer buf, Bool collectAll)
|
||||
{
|
||||
AMC amc;
|
||||
AMC amc = MustBeA(AMCZPool, pool);
|
||||
|
||||
AVERT(Pool, pool);
|
||||
amc = PoolAMC(pool);
|
||||
AVERT(AMC, amc);
|
||||
AVERT(Buffer, buf);
|
||||
AVERT(Bool, collectAll);
|
||||
UNUSED(collectAll); /* obsolete */
|
||||
|
|
@ -1059,11 +1043,8 @@ static void AMCRampBegin(Pool pool, Buffer buf, Bool collectAll)
|
|||
|
||||
static void AMCRampEnd(Pool pool, Buffer buf)
|
||||
{
|
||||
AMC amc;
|
||||
AMC amc = MustBeA(AMCZPool, pool);
|
||||
|
||||
AVERT(Pool, pool);
|
||||
amc = PoolAMC(pool);
|
||||
AVERT(AMC, amc);
|
||||
AVERT(Buffer, buf);
|
||||
|
||||
AVER(amc->rampCount > 0);
|
||||
|
|
@ -1121,15 +1102,12 @@ static Res AMCWhiten(Pool pool, Trace trace, Seg seg)
|
|||
{
|
||||
Size condemned = 0;
|
||||
amcGen gen;
|
||||
AMC amc;
|
||||
AMC amc = MustBeA(AMCZPool, pool);
|
||||
Buffer buffer;
|
||||
amcSeg amcseg;
|
||||
amcSeg amcseg = MustBeA(amcSeg, seg);
|
||||
Res res;
|
||||
|
||||
AVERT(Pool, pool);
|
||||
AVERT(Trace, trace);
|
||||
AVERT(Seg, seg);
|
||||
amcseg = Seg2amcSeg(seg);
|
||||
|
||||
buffer = SegBuffer(seg);
|
||||
if(buffer != NULL) {
|
||||
|
|
@ -1194,9 +1172,6 @@ static Res AMCWhiten(Pool pool, Trace trace, Seg seg)
|
|||
condemned += SegSize(seg);
|
||||
trace->condemned += condemned;
|
||||
|
||||
amc = PoolAMC(pool);
|
||||
AVERT(AMC, amc);
|
||||
|
||||
gen = amcSegGen(seg);
|
||||
AVERT(amcGen, gen);
|
||||
if (!amcseg->old) {
|
||||
|
|
@ -1237,7 +1212,7 @@ static Res amcScanNailedRange(Bool *totalReturn, Bool *moreReturn,
|
|||
Format format;
|
||||
Size headerSize;
|
||||
Addr p, clientLimit;
|
||||
Pool pool = AMCPool(amc);
|
||||
Pool pool = MustBeA(AbstractPool, amc);
|
||||
format = pool->format;
|
||||
headerSize = format->headerSize;
|
||||
p = AddrAdd(base, headerSize);
|
||||
|
|
@ -1368,15 +1343,12 @@ static Res AMCScan(Bool *totalReturn, ScanState ss, Pool pool, Seg seg)
|
|||
{
|
||||
Addr base, limit;
|
||||
Format format;
|
||||
AMC amc;
|
||||
AMC amc = MustBeA(AMCZPool, pool);
|
||||
Res res;
|
||||
|
||||
AVER(totalReturn != NULL);
|
||||
AVERT(ScanState, ss);
|
||||
AVERT(Seg, seg);
|
||||
AVERT(Pool, pool);
|
||||
amc = PoolAMC(pool);
|
||||
AVERT(AMC, amc);
|
||||
|
||||
|
||||
format = pool->format;
|
||||
|
|
@ -1475,18 +1447,14 @@ static Res AMCFixEmergency(Pool pool, ScanState ss, Seg seg,
|
|||
Ref *refIO)
|
||||
{
|
||||
Arena arena;
|
||||
AMC amc;
|
||||
Addr newRef;
|
||||
|
||||
AVERT(Pool, pool);
|
||||
AVERC(AMCZPool, pool);
|
||||
AVERT(ScanState, ss);
|
||||
AVERT(Seg, seg);
|
||||
AVER(refIO != NULL);
|
||||
|
||||
arena = PoolArena(pool);
|
||||
AVERT(Arena, arena);
|
||||
amc = PoolAMC(pool);
|
||||
AVERT(AMC, amc);
|
||||
|
||||
ss->wasMarked = TRUE;
|
||||
|
||||
|
|
@ -1566,7 +1534,7 @@ static Res AMCFix(Pool pool, ScanState ss, Seg seg, Ref *refIO)
|
|||
return ResOK;
|
||||
}
|
||||
|
||||
amc = PoolAMC(pool);
|
||||
amc = MustBeA(AMCZPool, pool); /* FIXME: CRITICAL */
|
||||
AVERT_CRITICAL(AMC, amc);
|
||||
format = pool->format;
|
||||
headerSize = format->headerSize;
|
||||
|
|
@ -1677,15 +1645,13 @@ static void amcReclaimNailed(Pool pool, Trace trace, Seg seg)
|
|||
Size bytesReclaimed = (Size)0;
|
||||
Count preservedInPlaceCount = (Count)0;
|
||||
Size preservedInPlaceSize = (Size)0;
|
||||
AMC amc;
|
||||
AMC amc = MustBeA(AMCZPool, pool);
|
||||
Size headerSize;
|
||||
Addr padBase; /* base of next padding object */
|
||||
Size padLength; /* length of next padding object */
|
||||
|
||||
/* All arguments AVERed by AMCReclaim */
|
||||
|
||||
amc = PoolAMC(pool);
|
||||
AVERT(AMC, amc);
|
||||
format = pool->format;
|
||||
|
||||
arena = PoolArena(pool);
|
||||
|
|
@ -1779,12 +1745,9 @@ static void amcReclaimNailed(Pool pool, Trace trace, Seg seg)
|
|||
*/
|
||||
static void AMCReclaim(Pool pool, Trace trace, Seg seg)
|
||||
{
|
||||
AMC amc;
|
||||
AMC amc = MustBeA(AMCZPool, pool); /* FIXME: CRITICAL */
|
||||
amcGen gen;
|
||||
|
||||
AVERT_CRITICAL(Pool, pool);
|
||||
amc = PoolAMC(pool);
|
||||
AVERT_CRITICAL(AMC, amc);
|
||||
AVERT_CRITICAL(Trace, trace);
|
||||
AVERT_CRITICAL(Seg, seg);
|
||||
|
||||
|
|
@ -1825,10 +1788,9 @@ static void AMCWalk(Pool pool, Seg seg, FormattedObjectsVisitor f,
|
|||
void *p, size_t s)
|
||||
{
|
||||
Addr object, nextObject, limit;
|
||||
AMC amc;
|
||||
Format format;
|
||||
|
||||
AVERT(Pool, pool);
|
||||
AVERC(AMCZPool, pool);
|
||||
AVERT(Seg, seg);
|
||||
AVER(FUNCHECK(f));
|
||||
/* p and s are arbitrary closures so can't be checked */
|
||||
|
|
@ -1843,8 +1805,6 @@ static void AMCWalk(Pool pool, Seg seg, FormattedObjectsVisitor f,
|
|||
if(SegWhite(seg) == TraceSetEMPTY && SegGrey(seg) == TraceSetEMPTY
|
||||
&& SegNailed(seg) == TraceSetEMPTY)
|
||||
{
|
||||
amc = PoolAMC(pool);
|
||||
AVERT(AMC, amc);
|
||||
format = pool->format;
|
||||
|
||||
/* If the segment is buffered, only walk as far as the end */
|
||||
|
|
@ -1976,14 +1936,10 @@ static Res AMCAddrObject(Addr *pReturn, Pool pool, Seg seg, Addr addr)
|
|||
|
||||
static Size AMCTotalSize(Pool pool)
|
||||
{
|
||||
AMC amc;
|
||||
AMC amc = MustBeA(AMCZPool, pool);
|
||||
Size size = 0;
|
||||
Ring node, nextNode;
|
||||
|
||||
AVERT(Pool, pool);
|
||||
amc = PoolAMC(pool);
|
||||
AVERT(AMC, amc);
|
||||
|
||||
RING_FOR(node, &amc->genRing, nextNode) {
|
||||
amcGen gen = RING_ELT(amcGen, amcRing, node);
|
||||
AVERT(amcGen, gen);
|
||||
|
|
@ -1998,14 +1954,10 @@ static Size AMCTotalSize(Pool pool)
|
|||
|
||||
static Size AMCFreeSize(Pool pool)
|
||||
{
|
||||
AMC amc;
|
||||
AMC amc = MustBeA(AMCZPool, pool);
|
||||
Size size = 0;
|
||||
Ring node, nextNode;
|
||||
|
||||
AVERT(Pool, pool);
|
||||
amc = PoolAMC(pool);
|
||||
AVERT(AMC, amc);
|
||||
|
||||
RING_FOR(node, &amc->genRing, nextNode) {
|
||||
amcGen gen = RING_ELT(amcGen, amcRing, node);
|
||||
AVERT(amcGen, gen);
|
||||
|
|
@ -2023,22 +1975,19 @@ static Size AMCFreeSize(Pool pool)
|
|||
static Res AMCDescribe(Pool pool, mps_lib_FILE *stream, Count depth)
|
||||
{
|
||||
Res res;
|
||||
AMC amc;
|
||||
AMC amc = CouldBeA(AMCZPool, pool);
|
||||
Ring node, nextNode;
|
||||
const char *rampmode;
|
||||
|
||||
if(!TESTT(Pool, pool))
|
||||
return ResFAIL;
|
||||
amc = PoolAMC(pool);
|
||||
if(!TESTT(AMC, amc))
|
||||
return ResFAIL;
|
||||
if(!TESTC(AMCZPool, amc))
|
||||
return ResPARAM;
|
||||
if(stream == NULL)
|
||||
return ResFAIL;
|
||||
return ResPARAM;
|
||||
|
||||
res = WriteF(stream, depth,
|
||||
(amc->rankSet == RankSetEMPTY) ? "AMCZ" : "AMC",
|
||||
" $P {\n", (WriteFP)amc, " pool $P ($U)\n",
|
||||
(WriteFP)AMCPool(amc), (WriteFU)AMCPool(amc)->serial,
|
||||
(WriteFP)pool, (WriteFU)pool->serial,
|
||||
NULL);
|
||||
if(res != ResOK)
|
||||
return res;
|
||||
|
|
@ -2069,7 +2018,7 @@ static Res AMCDescribe(Pool pool, mps_lib_FILE *stream, Count depth)
|
|||
|
||||
if(0) {
|
||||
/* SegDescribes */
|
||||
RING_FOR(node, &AMCPool(amc)->segRing, nextNode) {
|
||||
RING_FOR(node, &pool->segRing, nextNode) {
|
||||
Seg seg = RING_ELT(Seg, poolRing, node);
|
||||
res = AMCSegDescribe(seg, stream, depth + 2);
|
||||
if(res != ResOK)
|
||||
|
|
@ -2201,8 +2150,7 @@ static Bool AMCCheck(AMC amc)
|
|||
{
|
||||
CHECKS(AMC, amc);
|
||||
CHECKC(AMCZPool, amc);
|
||||
CHECKD(Pool, AMCPool(amc));
|
||||
CHECKL(IsA(AMCZPool, AMCPool(amc)));
|
||||
CHECKD(Pool, MustBeA(AbstractPool, amc));
|
||||
CHECKL(RankSetCheck(amc->rankSet));
|
||||
CHECKD_NOSIG(Ring, &amc->genRing);
|
||||
CHECKL(BoolCheck(amc->gensBooted));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue