From e2ea14a3f700e2823ad10e22faf1cafde0cfd1e2 Mon Sep 17 00:00:00 2001 From: Richard Brooksby Date: Thu, 8 Feb 1996 14:20:19 +0000 Subject: [PATCH] Mail.richard.1996-02-08.10-26 Copied from Perforce Change: 15204 ServerID: perforce.ravenbrook.com --- mps/src/assert.c | 46 +++++---- mps/src/buffer.c | 27 ++---- mps/src/format.c | 27 ++---- mps/src/lockan.c | 17 ++-- mps/src/lockw3.c | 16 +--- mps/src/meter.c | 18 ++-- mps/src/misc.h | 48 ++++++++-- mps/src/mpsi.c | 6 +- mps/src/mpstd.h | 19 ++-- mps/src/pool.c | 27 +++--- mps/src/poolmfs.c | 30 +++--- mps/src/poolmv.c | 36 +++---- mps/src/poolmv.h | 3 +- mps/src/pooln.c | 43 ++++----- mps/src/protsu.c | 6 +- mps/src/protw3.c | 8 +- mps/src/ref.c | 8 +- mps/src/shield.c | 149 ++++++++++------------------- mps/src/testlib.c | 6 +- mps/src/than.c | 21 ++--- mps/src/thw3i3.c | 19 +--- mps/src/trace.c | 236 ++++++++++------------------------------------ mps/src/vman.c | 35 +++---- mps/src/vmsu.c | 22 ++--- mps/src/vmw3.c | 22 ++--- 25 files changed, 347 insertions(+), 548 deletions(-) diff --git a/mps/src/assert.c b/mps/src/assert.c index 3900c6649b2..b23d560a130 100644 --- a/mps/src/assert.c +++ b/mps/src/assert.c @@ -1,48 +1,54 @@ -/* ==== ASSERTION ==== +/* impl.c.assert: ASSERTION IMPLEMENTATION * - * $HopeName: MMsrc!assert.c(trunk.1) $ + * $HopeName: MMsrc!assert.c(trunk.2) $ * - * Copyright (C) 1994,1995 Harlequin Group, all rights reserved + * When DEBUG is defined (see debug.h) this source provides + * the AssertFail function which is invoked by the assertion macros + * (see impl.h.assert). It also provides for user-installed + * assertion failure handlers. * - * When DEBUG_ASSERT is defined (see debug.h) this source provides - * the AssertFail function which is invoked by the ASSERT macros - * (see assert.h). It produces no code otherwise. + * Notes * - * Notes - * - * 3. To be really solid, assert should write the information into a - * buffer before reaching the handler, so that it can be recovered - * even if printing fails. richard 1994-11-15 - * - * 4. This file declares a static object. We said we wouldn't do - * that. richard 1994-11-15 + * 3. To be really solid, assert should write the information into a + * buffer before reaching the handler, so that it can be recovered + * even if printing fails. richard 1994-11-15 */ #include "std.h" #include "assert.h" -#include "asrtos.h" #include "lib.h" #include -static AssertHandler handler = AssertOS; +static void AssertLib(const char *cond, const char *id, + const char *file, unsigned line) +{ + LibFormat(LibStreamErr(), + "\nMPS ASSERTION FAILURE\n\n" + "Id: %s\n" + "File: %s\n" + "Line: %u\n" + "Condition: %s\n\n", + id, file, line, cond); + LibAbort(); +} +static AssertHandler handler = AssertLib; AssertHandler AssertDefault(void) { - return(AssertOS); + return AssertLib; } - AssertHandler AssertInstall(AssertHandler new) { AssertHandler prev = handler; handler = new; - return(prev); + return prev; } -#ifdef DEBUG_ASSERT +#ifdef DEBUG /* === FAIL ASSERTION === diff --git a/mps/src/buffer.c b/mps/src/buffer.c index 9d33a968dac..3c3a6012ca2 100644 --- a/mps/src/buffer.c +++ b/mps/src/buffer.c @@ -2,7 +2,7 @@ * * ALLOCATION BUFFER IMPLEMENTATION * - * $HopeName: MMsrc!buffer.c(trunk.3) $ + * $HopeName: MMsrc!buffer.c(trunk.4) $ * * Copyright (C) 1995 Harlequin Group, all rights reserved * @@ -40,14 +40,14 @@ #include "buffer.h" #include "pool.h" #include "space.h" -#include "sched.h" #include "shield.h" #include "trace.h" +SRCID("$HopeName"); + -#ifdef DEBUG_SIGN static SigStruct BufferSigStruct; -#endif + DequeNode BufferPoolDeque(Buffer buffer) @@ -115,15 +115,13 @@ void BufferDestroy(Buffer buffer) } -#ifdef DEBUG_ASSERT +#ifdef DEBUG Bool BufferIsValid(Buffer buffer, ValidationType validParam) { AVER(buffer != NULL); -#ifdef DEBUG_SIGN AVER(ISVALIDNESTED(Sig, &BufferSigStruct)); AVER(buffer->sig == &BufferSigStruct); -#endif AVER(ISVALIDNESTED(DequeNode, &buffer->poolDeque)); AVER(buffer->base <= buffer->ap.init); AVER(buffer->ap.init <= buffer->ap.alloc); @@ -211,10 +209,8 @@ void BufferInit(Buffer buffer, Pool pool, DequeNodeInit(&buffer->poolDeque); DequeAppend(&pool->bufferDeque, &buffer->poolDeque); -#ifdef DEBUG_SIGN SigInit(&BufferSigStruct, "Buffer"); buffer->sig = &BufferSigStruct; -#endif AVER(ISVALID(Buffer, buffer)); } @@ -226,9 +222,7 @@ void BufferFinish(Buffer buffer) DequeNodeRemove(&buffer->poolDeque); -#ifdef DEBUG_SIGN buffer->sig = SigInvalid; -#endif } @@ -274,11 +268,6 @@ Error BufferFill(Addr *pReturn, Buffer buffer, Addr size) AVER(IsAligned(BufferPool(buffer)->alignment, size)); AVER(BufferIsReady(buffer)); - /* At every buffer fill, the scheduler gets to run a bit of work. */ - - if(!buffer->exposed) /* @@@@ Not when collecting! */ - SchedRun(SpaceSched(BufferSpace(buffer))); - e = (*buffer->fill)(pReturn, buffer, size); AVER(ISVALID(Buffer, buffer)); @@ -346,8 +335,7 @@ void BufferShieldExpose(Buffer buffer) /* @@@@ Assumes that the buffer buffers a segment. */ if(!BufferIsReset(buffer)) - ShieldExpose(SpaceShield(BufferSpace(buffer)), - buffer->base, buffer->ap.limit); + ShieldExpose(BufferSpace(buffer), buffer->base); } void BufferShieldCover(Buffer buffer) @@ -358,8 +346,7 @@ void BufferShieldCover(Buffer buffer) /* @@@@ Assumes that the buffer buffers a segment. */ if(!BufferIsReset(buffer)) - ShieldCover(SpaceShield(BufferSpace(buffer)), - buffer->base, buffer->ap.limit); + ShieldCover(BufferSpace(buffer), buffer->base); } diff --git a/mps/src/format.c b/mps/src/format.c index f23579cf61b..3ed44c49fa5 100644 --- a/mps/src/format.c +++ b/mps/src/format.c @@ -1,30 +1,27 @@ -/* impl.c.format +/* impl.c.format: OBJECT FORMATS * - * OBJECT FORMATS - * - * $HopeName: MMsrc!format.c(trunk.3) $ - * - * Copyright (C) 1995 Harlequin Group, all rights reserved + * $HopeName: MMsrc!format.c(trunk.4) $ */ #include "std.h" +#include "space.h" #include "format.h" +#include "pool.h" + +SRCID("$HopeName"); -#ifdef DEBUG_SIGN static struct SigStruct FormatSigStruct; -#endif -#ifdef DEBUG_ASSERT + +#ifdef DEBUG Bool FormatIsValid(Format format, ValidationType validParam) { AVER(format != NULL); -#ifdef DEBUG_SIGN AVER(ISVALIDNESTED(Sig, &FormatSigStruct)); AVER(format->sig == &FormatSigStruct); -#endif AVER(ISVALIDNESTED(Space, format->space)); AVER(IsPoT(format->alignment)); /* **** alignment should be less than maximum allowed */ @@ -33,10 +30,10 @@ Bool FormatIsValid(Format format, ValidationType validParam) AVER(format->move != NULL); AVER(format->isMoved != NULL); AVER(format->copy != NULL); - return(TRUE); + return TRUE; } -#endif /* DEBUG_ASSERT */ +#endif /* DEBUG */ Error FormatCreate(Format *formatReturn, Space space, @@ -65,10 +62,8 @@ Error FormatCreate(Format *formatReturn, Space space, format->isMoved = isMoved; format->copy = copy; -#ifdef DEBUG_SIGN SigInit(&FormatSigStruct, "Format"); format->sig = &FormatSigStruct; -#endif AVER(ISVALID(Format, format)); @@ -80,9 +75,7 @@ Error FormatCreate(Format *formatReturn, Space space, void FormatDestroy(Format format) { AVER(ISVALID(Format, format)); -#ifdef DEBUG_SIGN format->sig = SigInvalid; -#endif PoolFree(SpaceControlPool(format->space), (Addr)format, sizeof(FormatStruct)); diff --git a/mps/src/lockan.c b/mps/src/lockan.c index b8514c0325c..343cb3f5073 100644 --- a/mps/src/lockan.c +++ b/mps/src/lockan.c @@ -2,7 +2,7 @@ * * ANSI RECURSIVE LOCKS * - * $HopeName$ + * $HopeName: MMsrc!lockan.c(trunk.1) $ * * Copyright (C) 1995 Harlequin Group, all rights reserved * @@ -21,18 +21,17 @@ #include "lock.h" #include "lockst.h" -#ifdef DEBUG_SIGN -static SigStruct LockSigStruct; -#endif +SRCID("$HopeName"); -#ifdef DEBUG_ASSERT +static SigStruct LockSigStruct; + + +#ifdef DEBUG Bool LockIsValid(Lock lock, ValidationType validParam) { -#ifdef DEBUG_SIGN AVER(ISVALIDNESTED(Sig, &LockSigStruct)); AVER(lock->sig == &LockSigStruct); -#endif return TRUE; } @@ -42,10 +41,8 @@ void LockInit(Lock lock) { AVER(lock != NULL); lock->claims = 0; -#ifdef DEBUG_SIGN SigInit(&LockSigStruct, "Lock"); lock->sig = &LockSigStruct; -#endif AVER(ISVALID(Lock, lock)); } @@ -53,9 +50,7 @@ void LockFinish(Lock lock) { AVER(ISVALID(Lock, lock)); AVER(lock->claims == 0); -#ifdef DEBUG_SIGN lock->sig = SigInvalid; -#endif } void LockClaim(Lock lock) diff --git a/mps/src/lockw3.c b/mps/src/lockw3.c index bc4ac1e29ce..cc61dfeefb7 100644 --- a/mps/src/lockw3.c +++ b/mps/src/lockw3.c @@ -2,7 +2,7 @@ * * RECURSIVE LOCKS IN WIN32 * - * $HopeName$ + * $HopeName: MMsrc!locknt.c(trunk.1) $ * * Copyright (C) 1995 Harlequin Group, all rights reserved * @@ -34,18 +34,16 @@ #include -#ifdef DEBUG_SIGN -static SigStruct LockSigStruct; -#endif +SRCID("$HopeName"); -#ifdef DEBUG_ASSERT +static SigStruct LockSigStruct; + +#ifdef DEBUG Bool LockIsValid(Lock lock, ValidationType validParam) { -#ifdef DEBUG_SIGN AVER(ISVALIDNESTED(Sig, &LockSigStruct)); AVER(lock->sig == &LockSigStruct); -#endif return TRUE; } @@ -56,10 +54,8 @@ void LockInit(Lock lock) AVER(lock != NULL); lock->claims = 0; InitializeCriticalSection(&lock->cs); -#ifdef DEBUG_SIGN SigInit(&LockSigStruct, "Lock"); lock->sig = &LockSigStruct; -#endif AVER(ISVALID(Lock, lock)); } @@ -69,9 +65,7 @@ void LockFinish(Lock lock) /* Lock should not be finished while held */ AVER(lock->claims == 0); DeleteCriticalSection(&lock->cs); -#ifdef DEBUG_SIGN lock->sig = SigInvalid; -#endif } void LockClaim(Lock lock) diff --git a/mps/src/meter.c b/mps/src/meter.c index 8da8fd8a937..445e2c30b16 100644 --- a/mps/src/meter.c +++ b/mps/src/meter.c @@ -1,6 +1,6 @@ /* ==== METERING ==== * - * $HopeName$ + * $HopeName: MMsrc!meter.c(trunk.1) $ * * Copyright (C) 1995 Harlequin Group, all rights reserved * @@ -20,8 +20,10 @@ #include "lib.h" #include "meter.h" +SRCID("$HopeName"); -#ifdef DEBUG_ASSERT + +#ifdef DEBUG Bool MeterIsValid(Meter meter, ValidationType validParam) { unsigned i; @@ -33,11 +35,11 @@ Bool MeterIsValid(Meter meter, ValidationType validParam) for(i=0; iobservers; ++i) { AVER(ISVALIDNESTED(MeterObserver, &meter->observer[i])); } - return(TRUE); + return TRUE; } -#endif /* DEBUG_ASSERT */ +#endif /* DEBUG */ -#ifdef DEBUG_ASSERT +#ifdef DEBUG Bool MeterObserverIsValid(MeterObserver observer, ValidationType validParam) { @@ -48,9 +50,9 @@ Bool MeterObserverIsValid(MeterObserver observer, AVER(observer->f != NULL); /* p */ /* i */ - return(TRUE); + return TRUE; } -#endif /* DEBUG_ASSERT */ +#endif /* DEBUG */ void MeterEnable(Meter meter) { @@ -68,7 +70,7 @@ void MeterDisable(Meter meter) Error MeterStream(LibStream *streamReturn) { - return(LibStreamMeter(streamReturn)); + return LibStreamMeter(streamReturn); } void MeterObserverPrint(Meter meter, int index, diff --git a/mps/src/misc.h b/mps/src/misc.h index f8473c9bec4..2ce97663bfb 100644 --- a/mps/src/misc.h +++ b/mps/src/misc.h @@ -1,6 +1,6 @@ /* ==== MISCELLANEOUS DEFINITIONS ==== * - * $HopeName$ + * $HopeName: MMsrc!misc.h(trunk.1) $ * * Copyright (C) 1994,1995 Harlequin Group, all rights reserved * @@ -16,11 +16,31 @@ #ifndef misc_h #define misc_h -#include "arch.h" -#include "types.h" #include +/* === MACRO BRACKETS === + * + * M_BEGIN and M_END should be used to bracked ALL multi-statement macros. + * This ensures that such macros can be used in all statement contexts, + * including in the first branch of an if() statement which has an else + * clause. + */ + +#define M_BEGIN do { +#define M_END } while(0) + + +/* === STRINGIZING MACROS === + * + * M_STRING() converts into a quoted string "" + * M_STR() does the same after substituting macros into . + */ + +#define M_STRING(s) #s +#define M_STR(s) M_STRING(s) + + /* == Null Statement == * * Do not be tempted to use NULL, or just semicolon as the null statement. @@ -57,6 +77,22 @@ #define forever for(;;) /* loop indefinitely */ +/* == Boolean == + * + * Using a boolean type in C is a tricky thing. Non-zero values are + * "true" but are not all equal to TRUE. The Bool type is therefore + * mostly defined so that the intention of the code is clearer. + * Use with care. + */ + +enum +{ + FALSE = 0, + TRUE = 1 +}; +typedef int Bool; + + /* == Align Address == * * AlignUp rounds up an Addr to the nearest N-boundary with N is a positive @@ -66,12 +102,6 @@ * two. */ -#ifndef DEBUG_NOINLINE -#define AlignUp(pot, i) (((Addr)(i)+(Addr)(pot)-1)&~((Addr)(pot)-1)) -#define IsAligned(pot, i) (((Addr)(i) & ((Addr)(pot)-1)) == 0) -#define IsPoT(pot) ((pot)>0 && ((pot)&((pot)-1))==0) -#endif - extern Addr (AlignUp)(Addr pot, Addr i); extern Bool (IsAligned)(Addr pot, Addr i); extern Bool (IsPoT)(Addr pot); diff --git a/mps/src/mpsi.c b/mps/src/mpsi.c index e1fff9bdc4e..9667b524f30 100644 --- a/mps/src/mpsi.c +++ b/mps/src/mpsi.c @@ -15,10 +15,12 @@ #include #include +SRCID("$HopeName"); + /* Check consistency of interface mappings. */ -#ifdef DEBUG_ASSERT +#ifdef DEBUG static Bool mpsi_check(void) { @@ -59,7 +61,7 @@ static Bool mpsi_check(void) return TRUE; } -#endif /* DEBUG_ASSERT */ +#endif /* DEBUG */ mps_assert_t mps_assert_install(mps_assert_t handler) { diff --git a/mps/src/mpstd.h b/mps/src/mpstd.h index dd3fb6ef294..2ca5bbad3b2 100644 --- a/mps/src/mpstd.h +++ b/mps/src/mpstd.h @@ -1,14 +1,14 @@ -/* impl.h.mpstd: HARLEQUIN MEMORY POOL SYSTEM TARGET DETECTION */ +/* impl.h.mpstd: HARLEQUIN MEMORY POOL SYSTEM TARGET DETECTION + * + * Detect the target platform using predefined preprocessor symbols + * defined by the build environment. The symbols are derived from the + * documentation, or, in the case of GCC, from the compiler itself. + * References to the documentation appear above each detection line. + */ #ifndef mpstd_h #define mpstd_h - -/* Detect the target platform using predefined preprocessor symbols */ -/* defined by the build environment. The symbols are derived from the */ -/* documentation, or, in the case of GCC, from the compiler itself. */ -/* References to the documentation appear above each detection line. */ - /* Visual C++ 2.0, Books Online, C/C++ Book, Preprocessor Reference, */ /* Chapter 1: The Preprocessor, Macros, Predefined Macros. */ @@ -20,6 +20,7 @@ #define MPS_T_WORD unsigned long #define MPS_WORD_WIDTH 32 #define MPS_WORD_SHIFT 5 +#define MPS_PF_ALIGN 4 /* MW C/C++/ASM Lang Ref, pp175-176. Metrowerks does not document */ /* a way to determine the OS -- we assume MacOS 7. */ @@ -32,6 +33,7 @@ #define MPS_T_WORD unsigned long #define MPS_WORD_WIDTH 32 #define MPS_WORD_SHIFT 5 +#define MPS_PF_ALIGN 1 /* GCC 2.5.8, gcc -E -dM, (__SVR4 indicates Solaris) */ @@ -44,6 +46,7 @@ #define MPS_T_WORD unsigned long #define MPS_WORD_WIDTH 32 #define MPS_WORD_SHIFT 5 +#define MPS_PF_ALIGN 8 /* GCC 2.6.3, gcc -E -dM */ @@ -56,6 +59,7 @@ #define MPS_T_SHORT unsigned #define MPS_WORD_WIDTH 64 #define MPS_WORD_SHIFT 6 +#define MPS_PF_ALIGN 8 /* GCC 2.6.3, gcc -E -dM */ @@ -67,6 +71,7 @@ #define MPS_T_WORD unsigned long #define MPS_WORD_WIDTH 32 #define MPS_WORD_SHIFT 5 +#define MPS_PF_ALIGN 4 #else #error "Unable to detect target platform" diff --git a/mps/src/pool.c b/mps/src/pool.c index 1cd831cd2da..a4c1cdabe8f 100644 --- a/mps/src/pool.c +++ b/mps/src/pool.c @@ -1,6 +1,6 @@ /* ==== POOLS ==== * - * $HopeName: MMsrc!pool.c(trunk.6) $ + * $HopeName: MMsrc!pool.c(trunk.7) $ * * Copyright (C) 1994,1995 Harlequin Group, all rights reserved * @@ -23,21 +23,20 @@ #include #include +SRCID("$HopeName"); + -#ifdef DEBUG_SIGN static SigStruct PoolSigStruct; -#endif -#ifdef DEBUG_ASSERT + +#ifdef DEBUG Bool PoolIsValid(Pool pool, ValidationType validParam) { AVER(pool != NULL); -#ifdef DEBUG_SIGN AVER(ISVALIDNESTED(Sig, &PoolSigStruct)); AVER(pool->sig == &PoolSigStruct); -#endif AVER(ISVALIDNESTED(DequeNode, &pool->spaceDeque)); AVER(ISVALIDNESTED(Deque, &pool->segDeque)); AVER(ISVALIDNESTED(Deque, &pool->bufferDeque)); @@ -45,7 +44,7 @@ Bool PoolIsValid(Pool pool, ValidationType validParam) return TRUE; } -#endif /* DEBUG_ASSERT */ +#endif /* DEBUG */ void PoolInit(Pool pool, Space space, PoolClass class) @@ -59,10 +58,8 @@ void PoolInit(Pool pool, Space space, PoolClass class) DequeInit(&pool->bufferDeque); pool->alignment = ARCH_ALIGNMOD; -#ifdef DEBUG_SIGN SigInit(&PoolSigStruct, "Pool"); pool->sig = &PoolSigStruct; -#endif AVER(ISVALID(Pool, pool)); @@ -80,9 +77,7 @@ void PoolFinish(Pool pool) DequeFinish(&pool->bufferDeque); DequeFinish(&pool->segDeque); -#ifdef DEBUG_SIGN pool->sig = SigInvalid; -#endif } @@ -277,7 +272,7 @@ Pool PoolOfSeg(Arena arena, Addr seg) pool = (Pool)ArenaGet(arena, seg, ARENA_POOL); AVER(ISVALID(Pool, pool)); - return(pool); + return pool; } Bool PoolOfAddr(Pool *poolReturn, Arena arena, Addr addr) @@ -291,10 +286,10 @@ Bool PoolOfAddr(Pool *poolReturn, Arena arena, Addr addr) { Pool pool = PoolOfSeg(arena, seg); *poolReturn = pool; - return(TRUE); + return TRUE; } - return(FALSE); + return FALSE; } @@ -307,9 +302,9 @@ Bool PoolHasAddr(Pool pool, Addr addr) arena = SpaceArena(PoolSpace(pool)); if(PoolOfAddr(&addrPool, arena, addr) && addrPool == pool) - return(TRUE); + return TRUE; else - return(FALSE); + return FALSE; } diff --git a/mps/src/poolmfs.c b/mps/src/poolmfs.c index 242cd1c38a5..9bdec0b4953 100644 --- a/mps/src/poolmfs.c +++ b/mps/src/poolmfs.c @@ -1,6 +1,6 @@ /* ==== MANUAL FIXED SMALL UNIT POOL ==== * - * $HopeName: MMsrc/!poolmfs.c(trunk.5)$ + * $HopeName: MMsrc!poolmfs.c(trunk.6) $ * * Copyright (C) 1994,1995 Harlequin Group, all rights reserved * @@ -44,6 +44,8 @@ #include #include +SRCID("$HopeName"); + /* == Round up == * @@ -75,7 +77,7 @@ PoolClass PoolClassMFS(void) NULL, NULL, /* fix, relcaim */ NULL, /* access */ describe); - return(&PoolClassMFSStruct); + return &PoolClassMFSStruct; } @@ -100,11 +102,11 @@ PoolMFSInfo PoolMFSGetInfo(void) { /* unitSizeMin */ UNIT_MIN }; - return(&info); + return &info; } -#ifdef DEBUG_ASSERT +#ifdef DEBUG Bool PoolMFSIsValid(PoolMFS poolMFS, ValidationType validParam) { @@ -117,16 +119,16 @@ Bool PoolMFSIsValid(PoolMFS poolMFS, ValidationType validParam) arena = SpaceArena(PoolSpace(&poolMFS->poolStruct)); AVER(IsAligned(ArenaGrain(arena), poolMFS->extendBy)); AVER(poolMFS->unitsPerSeg == poolMFS->extendBy/poolMFS->unitSize); - return(TRUE); + return TRUE; } -#endif /* DEBUG_ASSERT */ +#endif /* DEBUG */ Pool (PoolMFSPool)(PoolMFS poolMFS) { AVER(ISVALID(PoolMFS, poolMFS)); - return(&poolMFS->poolStruct); + return &poolMFS->poolStruct; } @@ -151,7 +153,7 @@ Error PoolMFSCreate(PoolMFS *poolMFSReturn, Space space, } *poolMFSReturn = poolMFS; - return(ErrSUCCESS); + return ErrSUCCESS; } static Error create(Pool *poolReturn, Space space, va_list arg) @@ -167,10 +169,10 @@ static Error create(Pool *poolReturn, Space space, va_list arg) unitSize = va_arg(arg, Size); e = PoolMFSCreate(&poolMFS, space, extendBy, unitSize); - if(e != ErrSUCCESS) return(e); + if(e != ErrSUCCESS) return e; *poolReturn = PoolMFSPool(poolMFS); - return(ErrSUCCESS); + return ErrSUCCESS; } @@ -215,7 +217,7 @@ Error PoolMFSInit(PoolMFS poolMFS, Space space, Size extendBy, AVER(ISVALID(PoolMFS, poolMFS)); - return(ErrSUCCESS); + return ErrSUCCESS; } @@ -251,7 +253,7 @@ static Error alloc(Addr *pReturn, Pool pool, Size size) Error e; PoolMFS MFS; -#ifndef DEBUG_ASSERT +#ifndef DEBUG UNUSED(size); #endif @@ -333,7 +335,7 @@ static void free_(Pool pool, Addr old, Size size) Header h; PoolMFS MFS; -#ifndef DEBUG_ASSERT +#ifndef DEBUG UNUSED(size); #endif @@ -376,6 +378,6 @@ static Error describe(Pool pool, LibStream stream) MFS->freeList, MFS->segList); - return(e); + return e; } diff --git a/mps/src/poolmv.c b/mps/src/poolmv.c index cafd5a47b56..cf181383c3b 100644 --- a/mps/src/poolmv.c +++ b/mps/src/poolmv.c @@ -1,6 +1,6 @@ /* ==== MANUAL VARIABLE POOL ==== * - * $HopeName: MMsrc!poolmv.c(trunk.6) $ + * $HopeName: MMsrc!poolmv.c(trunk.7) $ * * Copyright (C) 1994, 1995 Harlequin Group, all rights reserved * @@ -43,6 +43,8 @@ #include "poolmfs.h" #include +SRCID("$HopeName"); + #define BLOCKPOOL(mv) (PoolMFSPool(&(mv)->blockPoolStruct)) #define SPANPOOL(mv) (PoolMFSPool(&(mv)->spanPoolStruct)) @@ -70,7 +72,7 @@ PoolClass PoolClassMV(void) NULL, NULL, /* fix, relcaim */ NULL, /* access */ describe); - return(&PoolClassMVStruct); + return &PoolClassMVStruct; } @@ -89,7 +91,7 @@ typedef struct BlockStruct } BlockStruct, *Block; -#ifdef DEBUG_ASSERT +#ifdef DEBUG static Bool BlockIsValid(Block block, ValidationType validParam) { @@ -98,7 +100,7 @@ static Bool BlockIsValid(Block block, ValidationType validParam) /* Check that it is in the block pool. See note 7. */ /* This turns out to be considerably tricky, as we cannot get hold * of the blockPool (pool is not a parameter). */ - return(TRUE); + return TRUE; } #endif @@ -125,7 +127,7 @@ typedef struct SpanStruct } SpanStruct, *Span; -#ifdef DEBUG_ASSERT +#ifdef DEBUG static Bool SpanIsValid(Span span, ValidationType validParam) { @@ -158,13 +160,13 @@ static Bool SpanIsValid(Span span, ValidationType validParam) /* Check that it is in the span pool. See note 7. */ - return(TRUE); + return TRUE; } #endif -#ifdef DEBUG_ASSERT +#ifdef DEBUG Bool PoolMVIsValid(PoolMV poolMV, ValidationType validParam) { @@ -177,16 +179,16 @@ Bool PoolMVIsValid(PoolMV poolMV, ValidationType validParam) /* Could do more checks here. */ - return(TRUE); + return TRUE; } -#endif /* DEBUG_ASSERT */ +#endif /* DEBUG */ Pool PoolMVPool(PoolMV poolMV) { AVER(ISVALID(PoolMV, poolMV)); - return(&poolMV->poolStruct); + return &poolMV->poolStruct; } @@ -202,7 +204,7 @@ Error PoolMVCreate(PoolMV *poolMVReturn, Space space, e = PoolAlloc((Addr *)&poolMV, SpaceControlPool(space), sizeof(PoolMVStruct)); if(e != ErrSUCCESS) - return(e); + return e; e = PoolMVInit(poolMV, space, extendBy, avgSize, maxSize); if(e != ErrSUCCESS) { @@ -211,7 +213,7 @@ Error PoolMVCreate(PoolMV *poolMVReturn, Space space, } *poolMVReturn = poolMV; - return(ErrSUCCESS); + return ErrSUCCESS; } static Error create(Pool *poolReturn, Space space, va_list arg) @@ -372,14 +374,14 @@ static Bool SpanAlloc(Addr *addrReturn, Span span, Addr size, span->space -= size; *addrReturn = new; - return(TRUE); + return TRUE; } block = block->next; } while(block->next != NULL); - return(FALSE); + return FALSE; } @@ -434,7 +436,7 @@ static Error SpanFree(Span span, Addr base, Addr limit, Pool blockPool) /* block must be split into two parts. */ e = PoolAlloc((Addr *)&new, blockPool, sizeof(BlockStruct)); - if(e != ErrSUCCESS) return(e); + if(e != ErrSUCCESS) return e; /* If the freed area is in the base sentinel then insert the new */ /* descriptor after it, otherwise insert before. */ @@ -464,7 +466,7 @@ static Error SpanFree(Span span, Addr base, Addr limit, Pool blockPool) span->space += limit - base; - return(ErrSUCCESS); + return ErrSUCCESS; } prev = &block->next; @@ -698,5 +700,5 @@ static Error describe(Pool pool, LibStream stream) span = span->next; } - return(ErrSUCCESS); + return ErrSUCCESS; } diff --git a/mps/src/poolmv.h b/mps/src/poolmv.h index 19c1074fc91..eae9a4ca6ea 100644 --- a/mps/src/poolmv.h +++ b/mps/src/poolmv.h @@ -1,6 +1,6 @@ /* ==== MANUAL VARIABLE POOLS ==== * - * $HopeName: MMsrc/!poolmv.h(trunk.1)$ + * $HopeName: MMsrc!poolmv.h(trunk.2) $ * * Copyright (C) 1994,1995 Harlequin Group, all rights reserved * @@ -47,6 +47,7 @@ #include "std.h" #include "pool.h" +#include "poolclas.h" #include "space.h" #include diff --git a/mps/src/pooln.c b/mps/src/pooln.c index 8099f331fb8..8e1bea6a203 100644 --- a/mps/src/pooln.c +++ b/mps/src/pooln.c @@ -2,7 +2,7 @@ * * NULL POOL * - * $HopeName: MMsrc/!pooln.c(trunk.2)$ + * $HopeName: MMsrc!pooln.c(trunk.3) $ * * Copyright(C) 1995 Harlequin Group, all rights reserved * @@ -23,10 +23,11 @@ #include "space.h" #include "trace.h" #include "prot.h" - #include #include +SRCID("$HopeName"); + /* Class's methods */ @@ -165,11 +166,11 @@ static Error alloc(Addr *pReturn, Pool pool, Size size) AVER(ISVALID(Pool, pool)); AVER(pool->class == &PoolClassNStruct); AVER(size > 0); -#ifndef DEBUG_ASSERT +#ifndef DEBUG UNUSED(pReturn); UNUSED(pool); UNUSED(size); -#endif /* DEBUG_ASSERT */ +#endif /* DEBUG */ return ErrLIMIT; /* limit of nil blocks exceeded */ } @@ -180,11 +181,11 @@ static void free_(Pool pool, Addr old, Size size) AVER(pool->class == &PoolClassNStruct); AVER(old != (Addr)0); AVER(size > 0); -#ifndef DEBUG_ASSERT +#ifndef DEBUG UNUSED(pool); UNUSED(old); UNUSED(size); -#endif /* DEBUG_ASSERT */ +#endif /* DEBUG */ NOTREACHED; /* can't allocate, should never free */ } @@ -194,10 +195,10 @@ static Error bufferCreate(Buffer *bufReturn, Pool pool) AVER(bufReturn != NULL); AVER(ISVALID(Pool, pool)); AVER(pool->class == &PoolClassNStruct); -#ifndef DEBUG_ASSERT +#ifndef DEBUG UNUSED(bufReturn); UNUSED(pool); -#endif /* DEBUG_ASSERT */ +#endif /* DEBUG */ return ErrLIMIT; /* limit of nil buffers exceeded */ } @@ -205,9 +206,9 @@ static Error bufferCreate(Buffer *bufReturn, Pool pool) static void bufferDestroy(Buffer buf) { AVER(ISVALID(Buffer, buf)); -#ifndef DEBUG_ASSERT +#ifndef DEBUG UNUSED(buf); -#endif /* DEBUG_ASSERT */ +#endif /* DEBUG */ NOTREACHED; /* can't create, so shouldn't destroy */ } @@ -224,9 +225,9 @@ static Error describe(Pool pool, LibStream stream) poolN = PARENT(PoolNStruct, poolStruct, pool); AVER(ISVALID(PoolN, poolN)); -#ifndef DEBUG_ASSERT +#ifndef DEBUG UNUSED(poolN); -#endif /* DEBUG_ASSERT */ +#endif /* DEBUG */ return ErrSUCCESS; } @@ -237,10 +238,10 @@ static Error condemn(Pool pool, Trace trace) AVER(ISVALID(Pool, pool)); AVER(pool->class == &PoolClassNStruct); AVER(ISVALID(Trace, trace)); -#ifndef DEBUG_ASSERT +#ifndef DEBUG UNUSED(pool); UNUSED(trace); -#endif /* DEBUG_ASSERT */ +#endif /* DEBUG */ return ErrSUCCESS; } @@ -250,7 +251,7 @@ static void mark(Pool pool, Trace trace) AVER(ISVALID(Pool, pool)); AVER(pool->class == &PoolClassNStruct); AVER(ISVALID(Trace, trace)); -#ifndef DEBUG_ASSERT +#ifndef DEBUG UNUSED(pool); UNUSED(trace); #endif @@ -262,11 +263,11 @@ static Error scan(Pool pool, Trace trace, RefRank rank) AVER(pool->class == &PoolClassNStruct); AVER(ISVALID(Trace, trace)); AVER(ISVALID(RefRank, rank)); -#ifndef DEBUG_ASSERT +#ifndef DEBUG UNUSED(pool); UNUSED(trace); UNUSED(rank); -#endif /* DEBUG_ASSERT */ +#endif /* DEBUG */ return ErrSUCCESS; } @@ -279,13 +280,13 @@ static Error fix(Pool pool, Trace trace, RefRank rank, AVER(ISVALID(Trace, trace)); AVER(ISVALID(RefRank, rank)); AVER(ISVALID(Arena, arena)); -#ifndef DEBUG_ASSERT +#ifndef DEBUG UNUSED(pool); UNUSED(trace); UNUSED(rank); UNUSED(arena); UNUSED(refIO); -#endif /* DEBUG_ASSERT */ +#endif /* DEBUG */ NOTREACHED; /* since we don't allocate any objects, should never * be called upon to fix a reference */ return ErrFAILURE; @@ -296,7 +297,7 @@ static void reclaim(Pool pool, Trace trace) AVER(ISVALID(Pool, pool)); AVER(pool->class == &PoolClassNStruct); AVER(ISVALID(Trace, trace)); -#ifndef DEBUG_ASSERT +#ifndef DEBUG UNUSED(pool); UNUSED(trace); #endif @@ -309,7 +310,7 @@ static void access(Pool pool, Addr seg, ProtMode mode) AVER(pool->class == &PoolClassNStruct); UNUSED(seg); UNUSED(mode); -#ifndef DEBUG_ASSERT +#ifndef DEBUG UNUSED(pool); #endif /* deal with access to segment */ diff --git a/mps/src/protsu.c b/mps/src/protsu.c index 8c7e2539601..4222f0910d1 100644 --- a/mps/src/protsu.c +++ b/mps/src/protsu.c @@ -2,7 +2,7 @@ * * PROTECTION FOR SUNOS * - * $HopeName: MMsrc/!protsu.c(trunk.1)$ + * $HopeName: MMsrc!protsu.c(trunk.2) $ * * Copyright (C) 1995 Harlequin Group, all rights reserved * @@ -27,6 +27,8 @@ #error "protsu.c is SunOS 4 specific, but OS_SUNOS is not set" #endif +SRCID("$HopeName"); + /* .hack.sigdfl */ #ifndef SIG_DFL @@ -176,7 +178,7 @@ void ProtSetup(void) void ProtSet(Addr base, Addr limit, ProtMode mode) { -#ifdef DEBUG_ASSERT +#ifdef DEBUG Addr grain = ProtGrain(); #endif int flags; diff --git a/mps/src/protw3.c b/mps/src/protw3.c index daf57208d6d..0dd680f7465 100644 --- a/mps/src/protw3.c +++ b/mps/src/protw3.c @@ -1,7 +1,7 @@ /* impl.c.protnt * * PROTECTION FOR WIN32 - * $HopeName: MMsrc/!protnt.c(trunk.1)$ + * $HopeName: MMsrc!protnt.c(trunk.2) $ * * Copyright (C) 1995 Harlequin Group, all rights reserved */ @@ -14,7 +14,9 @@ #error "protnt.c is Win32 specific, but OS_NT is not set" #endif -#include "windows.h" +#include + +SRCID("$HopeName"); Addr ProtGrain(void) @@ -38,7 +40,7 @@ void ProtSetup(void) void ProtSet(Addr base, Addr limit, ProtMode mode) { -#ifdef DEBUG_ASSERT +#ifdef DEBUG Addr grain = ProtGrain(); #endif DWORD newProtect; diff --git a/mps/src/ref.c b/mps/src/ref.c index cd1b4839c7b..e86ee31b93a 100644 --- a/mps/src/ref.c +++ b/mps/src/ref.c @@ -2,7 +2,7 @@ * * REFERENCES * - * $HopeName$ + * $HopeName: MMsrc!ref.c(trunk.1) $ * * Copyright (C) 1995 Harlequin Group, all rights reserved */ @@ -10,8 +10,10 @@ #include "std.h" #include "ref.h" +SRCID("$HopeName"); -#ifdef DEBUG_ASSERT + +#ifdef DEBUG Bool RefRankIsValid(RefRank rank, ValidationType validParam) { @@ -20,4 +22,4 @@ Bool RefRankIsValid(RefRank rank, ValidationType validParam) return TRUE; } -#endif /* DEBUG_ASSERT */ +#endif /* DEBUG */ diff --git a/mps/src/shield.c b/mps/src/shield.c index e62d1fbee1c..0515f97418c 100644 --- a/mps/src/shield.c +++ b/mps/src/shield.c @@ -1,173 +1,122 @@ -/* impl.c.shield +/* impl.c.shield: SHIELD IMPLEMENTATION * - * SHIELDING + * $HopeName: MMsrc!shield.c(trunk.2) $ * - * $HopeName: MMsrc/!shield.c(trunk.1)$ + * See: idea.shield, design.mps.shield. * - * Copyright (C) 1995 Harlequin Group, all rights reserved - * - * See: idea.shield, design.mps.shield. - * - * Invariant: The protected memory is a subset of the shielded memory when - * inside the shield, and the same set when outside. - * - * HACKY HACKY JOY JOY! + * Invariant: The protected memory is a subset of the shielded memory when + * inside the shield, and the same set when outside. */ #include "std.h" -#include "shield.h" -#include "shieldst.h" #include "space.h" +#include "shield.h" #include "prot.h" #include "poolar.h" +#include "th.h" +SRCID("$HopeName"); -#ifdef DEBUG_SIGN -static SigStruct ShieldSigStruct; -#endif - - -Bool ShieldIsValid(Shield shield, ValidationType validParam) +static void protect(Arena arena, Addr seg, ProtMode mode) { - AVER(shield != NULL); -#ifdef DEBUG_SIGN - AVER(ISVALIDNESTED(Sig, &ShieldSigStruct)); - AVER(shield->sig == &ShieldSigStruct); -#endif /* DEBUG_SIGN */ -/* AVER(ISVALIDNESTED(Space, shield->space)); @@@@ */ -/* AVER(ISVALIDNESTED(Bool, shield->inside)); */ - return TRUE; -} - - -void ShieldInit(Shield shield, Space space) -{ - AVER(shield != NULL); - AVER(ISVALID(Space, space)); - - shield->inside = FALSE; - shield->space = space; - -#ifdef DEBUG_SIGN - SigInit(&ShieldSigStruct, "Shield"); - shield->sig = &ShieldSigStruct; -#endif /* DEBUG_SIGN */ - - AVER(ISVALID(Shield, shield)); -} - - -void ShieldFinish(Shield shield) -{ - AVER(!shield->inside); - -#ifdef DEBUG_SIGN - shield->sig = SigInvalid; -#endif -} - - -static void protect(Arena arena, Addr base, Addr limit, ProtMode mode) -{ - if(ArenaProtMode(arena, base) != mode) { - ProtSet(base, limit, mode); - ArenaSetProtMode(arena, base, mode); + if(ArenaProtMode(arena, seg) != mode) { + ProtSet(seg, seg + ArenaSegSize(arena, seg), mode); + ArenaSetProtMode(arena, seg, mode); } } - -void ShieldRaise(Shield shield, Addr base, Addr limit, ProtMode mode) +void ShieldRaise(Space space, Addr seg, ProtMode mode) { ProtMode shieldMode; Arena arena; - AVER(ISVALID(Shield, shield)); + AVER(ISVALID(Space, space)); - arena = SpaceArena(shield->space); + arena = SpaceArena(space); - shieldMode = ArenaShieldMode(arena, base); + shieldMode = ArenaShieldMode(arena, seg); AVER((shieldMode & mode) == ProtNONE); shieldMode |= mode; - ArenaSetShieldMode(arena, base, shieldMode); + ArenaSetShieldMode(arena, seg, shieldMode); if(shieldMode >> 2 == 0) - protect(arena, base, limit, shieldMode); + protect(arena, seg, shieldMode); } -void ShieldLower(Shield shield, Addr base, Addr limit, ProtMode mode) +void ShieldLower(Space space, Addr seg, ProtMode mode) { ProtMode shieldMode; Arena arena; - AVER(ISVALID(Shield, shield)); + AVER(ISVALID(Space, space)); - arena = SpaceArena(shield->space); + arena = SpaceArena(space); - shieldMode = ArenaShieldMode(arena, base); + shieldMode = ArenaShieldMode(arena, seg); AVER((shieldMode & mode) == mode); shieldMode &= ~mode; - ArenaSetShieldMode(arena, base, shieldMode); + ArenaSetShieldMode(arena, seg, shieldMode); if(shieldMode >> 2 == 0) - protect(arena, base, limit, shieldMode); /* will only remove protection */ + protect(arena, seg, shieldMode); /* will only remove protection */ } -void ShieldEnter(Shield shield) +void ShieldEnter(Space space) { - AVER(ISVALID(Shield, shield)); - AVER(!shield->inside); + AVER(ISVALID(Space, space)); + AVER(!space->insideShield); - ThreadDequeSuspend(SpaceThreadDeque(shield->space)); - shield->inside = TRUE; + ThreadDequeSuspend(SpaceThreadDeque(space)); + space->insideShield = TRUE; } -void ShieldLeave(Shield shield) +void ShieldLeave(Space space) { - AVER(ISVALID(Shield, shield)); - AVER(shield->inside); + AVER(ISVALID(Space, space)); + AVER(space->insideShield); /* .opt.lazy-cover: for all segs { - protect(arena, base, ArenaShieldMode(arena, base)); + protect(arena, seg, ArenaShieldMode(arena, seg)); } */ - ThreadDequeResume(SpaceThreadDeque(shield->space)); - shield->inside = FALSE; + ThreadDequeResume(SpaceThreadDeque(space)); + space->insideShield = FALSE; } -void ShieldExpose(Shield shield, Addr base, Addr limit) +void ShieldExpose(Space space, Addr seg) { ProtMode shieldMode; Arena arena; - AVER(ISVALID(Shield, shield)); - AVER(shield->inside); + AVER(ISVALID(Space, space)); + AVER(space->insideShield); - arena = SpaceArena(shield->space); - shieldMode = ArenaShieldMode(arena, base); + arena = SpaceArena(space); + shieldMode = ArenaShieldMode(arena, seg); shieldMode += 4; - ArenaSetShieldMode(arena, base, shieldMode); + ArenaSetShieldMode(arena, seg, shieldMode); - protect(arena, base, limit, ProtNONE); + protect(arena, seg, ProtNONE); } -void ShieldCover(Shield shield, Addr base, Addr limit) +void ShieldCover(Space space, Addr seg) { ProtMode shieldMode; Arena arena; - AVER(ISVALID(Shield, shield)); - AVER(ArenaProtMode(SpaceArena(shield->space), base) == ProtNONE); + AVER(ISVALID(Space, space)); + AVER(ArenaProtMode(SpaceArena(space), seg) == ProtNONE); - arena = SpaceArena(shield->space); - shieldMode = ArenaShieldMode(arena, base); + arena = SpaceArena(space); + shieldMode = ArenaShieldMode(arena, seg); AVER(shieldMode >= 4); shieldMode -= 4; - ArenaSetShieldMode(arena, base, shieldMode); + ArenaSetShieldMode(arena, seg, shieldMode); if(shieldMode >> 2 == 0) - protect(arena, base, limit, shieldMode); + protect(arena, seg, shieldMode); } diff --git a/mps/src/testlib.c b/mps/src/testlib.c index 4b67fddf71e..1e4d1de5f91 100644 --- a/mps/src/testlib.c +++ b/mps/src/testlib.c @@ -1,6 +1,6 @@ /* ==== TEST LIBRARY ==== * - * $Id: testlib.c,v 1.1 1995/04/13 17:00:20 drj Exp $ + * $Id: testlib.c,v 1.1 1995/09/07 13:49:58 richard Exp $ * * Copyright (C) 1995 Harlequin Group, all rights reserved * @@ -16,6 +16,8 @@ #include #include +SRCID("$HopeName"); + /* I nabbed it from "ML for the Working Programmer" * Originally from: * Stephen K Park & Keith W Miller (1988). Random number generators: @@ -29,7 +31,7 @@ unsigned long rnd(void) s *= 16807.0; s = fmod(s, 2147483647.0); /* 2^31 - 1 */ seed = (unsigned long)s; - return(seed); + return seed; } void die(Error e, const char *s) diff --git a/mps/src/than.c b/mps/src/than.c index f43737466cf..6924b8841f2 100644 --- a/mps/src/than.c +++ b/mps/src/than.c @@ -2,7 +2,7 @@ * * ANSI THREADS MANAGER * - * $HopeName: MMsrc!than.c(trunk.4) $ + * $HopeName: MMsrc!than.c(trunk.5) $ * * Copyright (C) 1995 Harlequin Group, all rights reserved * @@ -16,38 +16,35 @@ */ #include "std.h" +#include "space.h" #include "trace.h" #include "ref.h" -#include "space.h" #include "th.h" #include "ss.h" +SRCID("$HopeName"); + typedef struct ThreadStruct { -#ifdef DEBUG_SIGN Sig sig; -#endif DequeNodeStruct spaceDeque; /* attaches to space */ } ThreadStruct; -#ifdef DEBUG_SIGN static SigStruct ThreadSigStruct; -#endif -#ifdef DEBUG_ASSERT + +#ifdef DEBUG Bool ThreadIsValid(Thread thread, ValidationType validParam) { -#ifdef DEBUG_SIGN AVER(ISVALIDNESTED(Sig, &ThreadSigStruct)); AVER(thread->sig == &ThreadSigStruct); -#endif return TRUE; } -#endif /* DEBUG_ASSERT */ +#endif /* DEBUG */ Error ThreadRegister(Thread *threadReturn, Space space) @@ -65,10 +62,8 @@ Error ThreadRegister(Thread *threadReturn, Space space) DequeNodeInit(&thread->spaceDeque); -#ifdef DEBUG_SIGN SigInit(&ThreadSigStruct, "Thread"); thread->sig = &ThreadSigStruct; -#endif AVER(ISVALID(Thread, thread)); @@ -91,9 +86,7 @@ void ThreadDeregister(Thread thread, Space space) DequeNodeRemove(&thread->spaceDeque); -#ifdef DEBUG_SIGN thread->sig = SigInvalid; -#endif DequeNodeFinish(&thread->spaceDeque); diff --git a/mps/src/thw3i3.c b/mps/src/thw3i3.c index e40f746e017..9bcd5bffc00 100644 --- a/mps/src/thw3i3.c +++ b/mps/src/thw3i3.c @@ -2,7 +2,7 @@ * * WIN32 THREAD MANAGER * - * $HopeName: MMsrc!thnti3.c(trunk.3) $ + * $HopeName: MMsrc!thnti3.c(trunk.4) $ * * Copyright (C) 1995 Harlequin Group, all rights reserved * @@ -71,39 +71,34 @@ #include "space.h" #include "th.h" #include "ss.h" +#include +SRCID("$HopeName"); -#include "windows.h" typedef struct ThreadStruct { -#ifdef DEBUG_SIGN Sig sig; -#endif DequeNodeStruct spaceDeque; /* threads attached to space */ HANDLE handle; /* Handle of thread .thread.handle */ DWORD id; /* Thread id of thread */ } ThreadStruct; -#ifdef DEBUG_SIGN static SigStruct ThreadSigStruct; -#endif -#ifdef DEBUG_ASSERT +#ifdef DEBUG Bool ThreadIsValid(Thread thread, ValidationType validParam) { -#ifdef DEBUG_SIGN AVER(ISVALIDNESTED(Sig, &ThreadSigStruct)); AVER(thread->sig == &ThreadSigStruct); -#endif AVER(ISVALIDNESTED(DequeNode, &thread->spaceDeque)); return TRUE; } -#endif /* DEBUG_ASSERT */ +#endif /* DEBUG */ Error ThreadRegister(Thread *threadReturn, Space space) @@ -139,10 +134,8 @@ Error ThreadRegister(Thread *threadReturn, Space space) DequeNodeInit(&thread->spaceDeque); -#ifdef DEBUG_SIGN SigInit(&ThreadSigStruct, "Thread"); thread->sig = &ThreadSigStruct; -#endif AVER(ISVALID(Thread, thread)); @@ -164,9 +157,7 @@ void ThreadDeregister(Thread thread, Space space) DequeNodeRemove(&thread->spaceDeque); -#ifdef DEBUG_SIGN thread->sig = SigInvalid; -#endif DequeNodeFinish(&thread->spaceDeque); diff --git a/mps/src/trace.c b/mps/src/trace.c index a512dd4d021..d09b7cdb23f 100644 --- a/mps/src/trace.c +++ b/mps/src/trace.c @@ -1,193 +1,98 @@ - /* impl.c.trace +/* impl.c.trace: GENERIC TRACER IMPLEMENTATION * - * GENERIC TRACER IMPLEMENTATION - * - * $HopeName: MMsrc!trace.c(trunk.6) $ - * - * Copyright (C) 1995 Harlequin Group, all rights reserved - * - * This implements the Generic Tracer defined in impl.h.trace - * - * .single-collection: This implementation only supports a single - * concurrent collection. See issue.single-collection + * $HopeName: MMsrc!trace.c(trunk.7) $ */ #include "std.h" #include "lib.h" #include "mpmconf.h" #include "ref.h" -#include "refsig.h" -#include "trace.h" #include "space.h" +#include "trace.h" #include "pool.h" #include "root.h" #include "rootst.h" #include +SRCID("$HopeName"); + -#ifdef DEBUG_SIGN static SigStruct TraceSigStruct; -static SigStruct TraceSetSigStruct; -#endif -#define TRACEBIT(id) ((Addr)((Addr)1 << (id))) - -#ifdef DEBUG_ASSERT - -Bool TraceIdIsValid(TraceId id, ValidationType validParam) -{ - AVER(id < TRACE_MAX); - return TRUE; -} - -Bool TraceSetIsValid(TraceSet set, ValidationType validParam) -{ - AVER(set != NULL); -#ifdef DEBUG_SIGN - AVER(ISVALIDNESTED(Sig, &TraceSetSigStruct)); - AVER(set->sig == &TraceSetSigStruct); -#endif - AVER(TRACE_MAX == ADDRWIDTH || set->bits < TRACEBIT(TRACE_MAX)); - return TRUE; -} +#ifdef DEBUG Bool TraceIsValid(Trace trace, ValidationType validParam) { RefRank rank; AVER(trace != NULL); -#ifdef DEBUG_SIGN AVER(ISVALIDNESTED(Sig, &TraceSigStruct)); AVER(trace->sig == &TraceSigStruct); -#endif - AVER(ISVALIDNESTED(TraceId, trace->id)); - AVER(ISVALIDNESTED(DequeNode, &trace->spaceDeque)); AVER(ISVALIDNESTED(Space, trace->space)); - AVER(ISVALIDNESTED(RefSig, trace->ss.condemned)); for(rank = 0; rank < RefRankMAX; ++rank) AVER(trace->work[rank].marked >= trace->work[rank].scanned); AVER(ISVALIDNESTED(RefRank, trace->rank)); + AVER(TraceSetIsMember(trace->space->busyTraces, + trace - trace->space->trace)); return TRUE; } -#endif /* DEBUG_ASSERT */ +#endif /* DEBUG */ -Error TraceSetInit(TraceSet set) -{ - AVER(set != NULL); - - /* Addr is used to implement the TraceSet as a bitset. */ - /* Check that it is big enough. */ - AVER(TRACE_MAX <= ADDRWIDTH); - - set->bits = (Addr)0; - -#ifdef DEBUG_SIGN - SigInit(&TraceSetSigStruct, "TraceSet"); - set->sig = &TraceSetSigStruct; -#endif - - AVER(ISVALID(TraceSet, set)); - - return ErrSUCCESS; -} - -void TraceSetFinish(TraceSet set) -{ - AVER(ISVALID(TraceSet, set)); -#ifdef DEBUG_SIGN - set->sig = SigInvalid; -#endif -} - -void TraceSetAdd(TraceSet set, TraceId id) -{ - AVER(ISVALID(TraceSet, set)); - AVER(ISVALID(TraceId, id)); - - set->bits |= TRACEBIT(id); -} - -void TraceSetDelete(TraceSet set, TraceId id) -{ - AVER(ISVALID(TraceSet, set)); - AVER(ISVALID(TraceId, id)); - - set->bits &= ~TRACEBIT(id); -} - -Bool TraceSetIsMember(TraceSet set, TraceId id) -{ - AVER(ISVALID(TraceSet, set)); - AVER(ISVALID(TraceId, id)); - - return (set->bits & TRACEBIT(id)) != 0; -} - -/* If there is a TraceId not in set, then find - * returns TRUE and puts this id in *idReturn. Otherwise - * FALSE is returned. - */ -static Bool find(TraceSet set, TraceId *idReturn) -{ - TraceId id; - for(id = 0; id < TRACE_MAX; ++id) - if(!TraceSetIsMember(set, id)) { - *idReturn = id; - return TRUE; - } - return FALSE; -} - -Error TraceInit(Trace trace, Space space) +Error TraceCreate(Trace *traceReturn, Space space) { RefRank rank; TraceId id; + Trace trace; /* .single-collection */ AVER(TRACE_MAX == 1); - AVER(trace != NULL); + AVER(traceReturn != NULL); AVER(ISVALID(Space, space)); /* allocate free TraceId */ - if(!find(SpaceTraceSet(space), &id)) - return ErrLIMIT; + for(id = 0; id < TRACE_MAX; ++id) + if(!TraceSetIsMember(space->busyTraces, id)) + goto found; + return ErrLIMIT; - DequeNodeInit(&trace->spaceDeque); - trace->id = id; +found: + trace = &space->trace[id]; trace->space = space; for(rank = 0; rank < RefRankMAX; ++rank) { trace->work[rank].scanned = 0; trace->work[rank].marked = 0; } trace->ss.fix = TraceFix; - trace->ss.zoneShift = 0; /* zoneShift */ - /* trace->ss.condemned = RefSigEmpty(SpaceArena(space)); */ - trace->ss.condemned = (Addr)-1; /* condemned */ - trace->ss.summary = 0; /* summary */ + trace->ss.zoneShift = space->zoneShift; + trace->ss.condemned = RefSetEmpty; + trace->ss.summary = RefSetEmpty; trace->rank = 0; /* current rank */ -#ifdef DEBUG_SIGN SigInit(&TraceSigStruct, "Trace"); trace->sig = &TraceSigStruct; -#endif - AVER(ISVALID(Trace, trace)); + space->busyTraces = TraceSetAdd(space->busyTraces, id); - TraceSetAdd(SpaceTraceSet(space), id); - DequeAppend(SpaceTraceDeque(space), &trace->spaceDeque); + AVER(ISVALID(Trace, trace)); return ErrSUCCESS; } -void TraceFinish(Trace trace) +void TraceDestroy(Trace trace) { - AVER(ISVALID(Trace, trace)); + Space space; + TraceId id; -#ifdef DEBUG_ASSERT + AVER(ISVALID(Trace, trace)); + + space = trace->space; + id = TraceTraceId(trace); + +#ifdef DEBUG { RefRank rank; @@ -197,50 +102,12 @@ void TraceFinish(Trace trace) } #endif - DequeNodeRemove(&trace->spaceDeque); - TraceSetDelete(SpaceTraceSet(trace->space), trace->id); + space->busyTraces = TraceSetDelete(space->busyTraces, id); -#ifdef DEBUG_SIGN trace->sig = SigInvalid; -#endif } -Error TraceCreate(Trace *traceReturn, Space space) -{ - Error e; - Trace trace; - Pool controlPool; - - AVER(traceReturn != NULL); - AVER(ISVALID(Space, space)); - - controlPool = SpaceControlPool(space); - - e = PoolAlloc((Addr *)&trace, controlPool, sizeof(TraceStruct)); - if(e != ErrSUCCESS) return e; - - e = TraceInit(trace, space); - if(e != ErrSUCCESS) { - PoolFree(controlPool, (Addr)trace, sizeof(TraceStruct)); - return e; - } - - *traceReturn = trace; - return ErrSUCCESS; -} - - -void TraceDestroy(Trace trace) -{ - Pool controlPool; - AVER(ISVALID(Trace, trace)); - controlPool = SpaceControlPool(trace->space);; - TraceFinish(trace); - PoolFree(controlPool, (Addr)trace, sizeof(TraceStruct)); -} - - Error TraceDescribe(Trace trace, LibStream stream) { RefRank rank; @@ -250,9 +117,9 @@ Error TraceDescribe(Trace trace, LibStream stream) LibFormat(stream, "Trace %p {\n" " space = %p\n" - " condemned refsig = %lX\n", + " condemned refset = %lX\n", (void *)trace, - (unsigned long)trace->id, + (unsigned long)TraceTraceId(trace), (void *)trace->space, (unsigned long)trace->ss.condemned); @@ -272,7 +139,7 @@ Error TraceDescribe(Trace trace, LibStream stream) TraceId TraceTraceId(Trace trace) { AVER(ISVALID(Trace, trace)); - return trace->id; + return trace - trace->space->trace; } Space TraceSpace(Trace trace) @@ -294,15 +161,14 @@ ScanState TraceScanState(Trace trace) } -void TraceCondemn(Trace trace, RefSig refsig) +void TraceCondemn(Trace trace, RefSet rs) { Arena arena; AVER(ISVALID(Trace, trace)); arena = SpaceArena(trace->space); - /* trace->ss.condemned = RefSigUnion(trace->ss.condemned, refsig, arena); */ - trace->ss.condemned = (Addr)-1; + trace->ss.condemned = RefSetUnion(trace->ss.condemned, rs); } @@ -365,11 +231,11 @@ Error TraceRunAtomic(Trace trace) { Error e; RefRank rank; - Shield shield; + Space space; AVER(ISVALID(Trace, trace)); - - shield = SpaceShield(trace->space); + + space = trace->space; /* At the moment we must scan all roots, because we don't have */ /* a mechanism for shielding them. There can't be any weak or */ @@ -380,11 +246,11 @@ Error TraceRunAtomic(Trace trace) Deque deque; DequeNode node; - ShieldEnter(shield); + ShieldEnter(space); trace->rank = rank; - deque = SpaceRootDeque(trace->space); + deque = SpaceRootDeque(space); node = DequeFirst(deque); while(node != DequeSentinel(deque)) { DequeNode next = DequeNodeNext(node); @@ -400,7 +266,7 @@ Error TraceRunAtomic(Trace trace) node = next; } - ShieldLeave(shield); + ShieldLeave(space); } return ErrSUCCESS; @@ -411,12 +277,12 @@ Error TraceRun(Trace trace, Bool *finishedReturn) { Error e; RefRank rank; - Shield shield; + Space space; AVER(ISVALID(Trace, trace)); AVER(finishedReturn != NULL); - - shield = SpaceShield(trace->space); + + space = trace->space; for(rank = 0; rank < RefRankMAX; ++rank) { @@ -426,9 +292,9 @@ Error TraceRun(Trace trace, Bool *finishedReturn) Deque deque; DequeNode node; - ShieldEnter(shield); + ShieldEnter(space); - deque = SpacePoolDeque(trace->space); + deque = SpacePoolDeque(space); node = DequeFirst(deque); while(node != DequeSentinel(deque)) { DequeNode next = DequeNodeNext(node); @@ -436,14 +302,14 @@ Error TraceRun(Trace trace, Bool *finishedReturn) e = PoolScan(pool, trace); if(e != ErrSUCCESS) { - ShieldLeave(shield); + ShieldLeave(space); return e; } node = next; } - ShieldLeave(shield); + ShieldLeave(space); *finishedReturn = FALSE; return ErrSUCCESS; diff --git a/mps/src/vman.c b/mps/src/vman.c index cb9d3a0cde5..0f0dff4599e 100644 --- a/mps/src/vman.c +++ b/mps/src/vman.c @@ -2,7 +2,7 @@ * * MALLOC-BASED PSUEDO-VIRTUAL MEMORY MAPPING * - * $HopeName: MMsrc/!vman.c(trunk.3)$ + * $HopeName: MMsrc!vman.c(trunk.4) $ * * Copyright (C) 1995 Harlequin Group, all rights reserved * @@ -27,17 +27,16 @@ #include #include +SRCID("$HopeName"); + -#ifdef DEBUG_SIGN static SigStruct VMSigStruct; -#endif + typedef struct VMStruct { -#ifdef DEBUG_SIGN Sig sig; -#endif Addr base, limit; /* boundaries of malloc'd memory */ void *block; /* pointer to malloc'd block, for free() */ } VMStruct; @@ -45,19 +44,17 @@ typedef struct VMStruct Addr VMGrain(void) { - return(VMAN_GRAIN); /* see .grain */ + return VMAN_GRAIN; /* see .grain */ } -#ifdef DEBUG_ASSERT +#ifdef DEBUG Bool VMIsValid(VM vm, ValidationType validParam) { AVER(vm != NULL); -#ifdef DEBUG_SIGN AVER(ISVALIDNESTED(Sig, vm->sig)); AVER(vm->sig == &VMSigStruct); -#endif AVER(vm->base != 0); AVER(vm->limit != 0); AVER(vm->base < vm->limit); @@ -65,10 +62,10 @@ Bool VMIsValid(VM vm, ValidationType validParam) AVER(IsAligned(VMAN_GRAIN, vm->limit)); AVER(vm->block != NULL); AVER(vm->block <= (void *)vm->base); - return(TRUE); + return TRUE; } -#endif /* DEBUG_ASSERT */ +#endif /* DEBUG */ Error VMCreate(VM *vmReturn, Addr size) @@ -80,7 +77,7 @@ Error VMCreate(VM *vmReturn, Addr size) AVER(sizeof(Addr) == sizeof(size_t)); /* must conform */ vm = (VM)malloc(sizeof(VMStruct)); - if(vm == NULL) return(ErrRESMEM); + if(vm == NULL) return ErrRESMEM; /* Note that because we add VMAN_GRAIN rather than VMAN_GRAIN-1 */ /* we are not in danger of overflowing vm->limit even if malloc */ @@ -89,7 +86,7 @@ Error VMCreate(VM *vmReturn, Addr size) vm->block = malloc((size_t)(size + VMAN_GRAIN)); if(vm->block == NULL) { free(vm); - return(ErrRESMEM); + return ErrRESMEM; } vm->base = AlignUp(VMAN_GRAIN, (Addr)vm->block); @@ -98,15 +95,13 @@ Error VMCreate(VM *vmReturn, Addr size) memset((void *)vm->base, VMAN_JUNKBYTE, (size_t)size); -#ifdef DEBUG_SIGN SigInit(&VMSigStruct, "VM"); vm->sig = &VMSigStruct; -#endif AVER(ISVALID(VM, vm)); *vmReturn = vm; - return(ErrSUCCESS); + return ErrSUCCESS; } @@ -114,9 +109,7 @@ void VMDestroy(VM vm) { AVER(ISVALID(VM, vm)); -#ifdef DEBUG_SIGN vm->sig = SigInvalid; -#endif memset((void *)vm->base, VMAN_JUNKBYTE, (size_t)(vm->limit - vm->base)); @@ -128,13 +121,13 @@ void VMDestroy(VM vm) Addr VMBase(VM vm) { AVER(ISVALID(VM, vm)); - return(vm->base); + return vm->base; } Addr VMLimit(VM vm) { AVER(ISVALID(VM, vm)); - return(vm->limit); + return vm->limit; } @@ -150,7 +143,7 @@ Error VMMap(VM vm, Addr base, Addr limit) memset((void *)base, (int)0, (size_t)(limit - base)); - return(ErrSUCCESS); + return ErrSUCCESS; } diff --git a/mps/src/vmsu.c b/mps/src/vmsu.c index 287a4073536..309b6c06bfd 100644 --- a/mps/src/vmsu.c +++ b/mps/src/vmsu.c @@ -2,7 +2,7 @@ * * VIRTUAL MEMORY MAPPING FOR SUNOS 4 * - * $HopeName: MMsrc/!vmsu.c(trunk.4)$ + * $HopeName: MMsrc!vmsu.c(trunk.5) $ * * Copyright (C) 1995 Harlequin Group, all rights reserved * @@ -49,6 +49,8 @@ #include #include +SRCID("$HopeName"); + /* Fix up unprototyped system calls. */ /* Note that these are not fixed up by std.h because that only fixes */ @@ -59,16 +61,12 @@ extern int munmap(caddr_t addr, int len); extern int getpagesize(void); -#ifdef DEBUG_SIGN static SigStruct VMSigStruct; -#endif typedef struct VMStruct { -#ifdef DEBUG_SIGN Sig sig; -#endif int zero_fd; /* file descriptor for /dev/zero */ int none_fd; /* fildes used for PROT_NONE (/etc/passwd) */ Addr base, limit; /* boundaries of reserved space */ @@ -86,15 +84,13 @@ Addr VMGrain(void) } -#ifdef DEBUG_ASSERT +#ifdef DEBUG Bool VMIsValid(VM vm, ValidationType validParam) { AVER(vm != NULL); -#ifdef DEBUG_SIGN AVER(ISVALIDNESTED(Sig, vm->sig)); AVER(vm->sig == &VMSigStruct); -#endif AVER(vm->zero_fd >= 0); AVER(vm->none_fd >= 0); AVER(vm->zero_fd != vm->none_fd); @@ -106,7 +102,7 @@ Bool VMIsValid(VM vm, ValidationType validParam) return(TRUE); } -#endif /* DEBUG_ASSERT */ +#endif /* DEBUG */ Error VMCreate(VM *vmReturn, Addr size) @@ -168,10 +164,8 @@ Error VMCreate(VM *vmReturn, Addr size) vm->base = (Addr)addr; vm->limit = vm->base + size; -#ifdef DEBUG_SIGN SigInit(&VMSigStruct, "VM"); vm->sig = &VMSigStruct; -#endif AVER(ISVALID(VM, vm)); @@ -191,9 +185,7 @@ void VMDestroy(VM vm) /* about to vanish completely. However, munmap might fail for some */ /* reason, and this would ensure that it was still discovered if sigs */ /* were being checked. */ -#ifdef DEBUG_SIGN vm->sig = SigInvalid; -#endif close(vm->zero_fd); close(vm->none_fd); @@ -220,7 +212,7 @@ Addr VMLimit(VM vm) Error VMMap(VM vm, Addr base, Addr limit) { -#ifdef DEBUG_ASSERT +#ifdef DEBUG Addr grain = VMGrain(); #endif @@ -251,7 +243,7 @@ Error VMMap(VM vm, Addr base, Addr limit) void VMUnmap(VM vm, Addr base, Addr limit) { caddr_t addr; -#ifdef DEBUG_ASSERT +#ifdef DEBUG Addr grain = VMGrain(); #endif diff --git a/mps/src/vmw3.c b/mps/src/vmw3.c index ba87eb85915..9fccce4b32f 100644 --- a/mps/src/vmw3.c +++ b/mps/src/vmw3.c @@ -2,7 +2,7 @@ * * VIRTUAL MEMORY MAPPING FOR WIN32 * - * $HopeName: MMsrc/!vmnt.c(trunk.2)$ + * $HopeName: MMsrc!vmnt.c(trunk.3) $ * * Copyright (C) 1995 Harlequin Group, all rights reserved * @@ -54,17 +54,15 @@ #include #include +SRCID("$HopeName"); + -#ifdef DEBUG_SIGN static SigStruct VMSigStruct; -#endif typedef struct VMStruct { -#ifdef DEBUG_SIGN Sig sig; -#endif Addr base, limit; /* boundaries of reserved space */ } VMStruct; @@ -85,15 +83,13 @@ Addr VMGrain(void) } -#ifdef DEBUG_ASSERT +#ifdef DEBUG Bool VMIsValid(VM vm, ValidationType validParam) { AVER(vm != NULL); -#ifdef DEBUG_SIGN AVER(ISVALIDNESTED(Sig, vm->sig)); AVER(vm->sig == &VMSigStruct); -#endif AVER(vm->base != 0); AVER(vm->limit != 0); AVER(vm->base < vm->limit); @@ -102,7 +98,7 @@ Bool VMIsValid(VM vm, ValidationType validParam) return(TRUE); } -#endif /* DEBUG_ASSERT */ +#endif /* DEBUG */ Error VMCreate(VM *vmReturn, Addr size) @@ -136,10 +132,8 @@ Error VMCreate(VM *vmReturn, Addr size) vm->limit = (Addr)base + size; AVER(vm->base < vm->limit); /* .assume.not-last */ -#ifdef DEBUG_SIGN SigInit(&VMSigStruct, "VM"); vm->sig = &VMSigStruct; -#endif AVER(ISVALID(VM, vm)); @@ -160,9 +154,7 @@ void VMDestroy(VM vm) /* This appears to be pretty pointless, since the vm descriptor page * is about to vanish completely. However, the VirtaulFree might * fail and it would be nice to have a dead sig there. */ -#ifdef DEBUG_SIGN vm->sig = SigInvalid; -#endif b = VirtualFree((LPVOID)vm->base, (DWORD)0, MEM_RELEASE); AVER(b == TRUE); @@ -188,7 +180,7 @@ Addr VMLimit(VM vm) Error VMMap(VM vm, Addr base, Addr limit) { LPVOID b; -#ifdef DEBUG_ASSERT +#ifdef DEBUG Addr grain = VMGrain(); #endif @@ -214,7 +206,7 @@ Error VMMap(VM vm, Addr base, Addr limit) void VMUnmap(VM vm, Addr base, Addr limit) { -#ifdef DEBUG_ASSERT +#ifdef DEBUG Addr grain = VMGrain(); #endif BOOL b;