diff --git a/mps/code/arena.c b/mps/code/arena.c index 519a85d735b..10985ad9ab6 100644 --- a/mps/code/arena.c +++ b/mps/code/arena.c @@ -6,7 +6,7 @@ * .sources: is the main design document. */ #include "tract.h" -#include "poolmv.h" +#include "poolmvff.h" #include "mpm.h" #include "cbs.h" #include "bt.h" @@ -17,7 +17,7 @@ SRCID(arena, "$Id$"); -#define ArenaControlPool(arena) MVPool(&(arena)->controlPoolStruct) +#define ArenaControlPool(arena) MVFFPool(&(arena)->controlPoolStruct) #define ArenaCBSBlockPool(arena) MFSPool(&(arena)->freeCBSBlockPoolStruct) #define ArenaFreeLand(arena) CBSLand(&(arena)->freeLandStruct) @@ -137,7 +137,7 @@ Bool ArenaCheck(Arena arena) CHECKL(BoolCheck(arena->poolReady)); if (arena->poolReady) { /* */ - CHECKD(MV, &arena->controlPoolStruct); + CHECKD(MVFF, &arena->controlPoolStruct); CHECKD(Reservoir, &arena->reservoirStruct); } @@ -469,8 +469,8 @@ Res ControlInit(Arena arena) AVER(!arena->poolReady); MPS_ARGS_BEGIN(args) { MPS_ARGS_ADD(args, MPS_KEY_EXTEND_BY, CONTROL_EXTEND_BY); - res = PoolInit(MVPool(&arena->controlPoolStruct), arena, - PoolClassMV(), args); + res = PoolInit(ArenaControlPool(arena), arena, + PoolClassMVFF(), args); } MPS_ARGS_END(args); if (res != ResOK) return res; @@ -486,7 +486,7 @@ void ControlFinish(Arena arena) AVERT(Arena, arena); AVER(arena->poolReady); arena->poolReady = FALSE; - PoolFinish(MVPool(&arena->controlPoolStruct)); + PoolFinish(ArenaControlPool(arena)); } diff --git a/mps/code/global.c b/mps/code/global.c index 354adb54a9a..b7070ec77da 100644 --- a/mps/code/global.c +++ b/mps/code/global.c @@ -507,10 +507,9 @@ void GlobalsPrepareToDestroy(Globals arenaGlobals) * 0. arena->freeCBSBlockPoolStruct * 1. arena->reservoirStruct * 2. arena->controlPoolStruct - * 3. arena->controlPoolStruct.blockPoolStruct - * 4. arena->controlPoolStruct.spanPoolStruct + * 3. arena->controlPoolStruct.cbsBlockPoolStruct */ - AVER(RingLength(&arenaGlobals->poolRing) == 5); + AVER(RingLength(&arenaGlobals->poolRing) == 4); } diff --git a/mps/code/mpmst.h b/mps/code/mpmst.h index a798cc71fc4..6cfa15b15ff 100644 --- a/mps/code/mpmst.h +++ b/mps/code/mpmst.h @@ -141,30 +141,6 @@ typedef struct MFSStruct { /* MFS outer structure */ } MFSStruct; -/* MVStruct -- MV (Manual Variable) pool outer structure - * - * .mv: See , . - * - * The MV pool outer structure is declared here because it is the - * control pool structure which is inlined in the arena. Normally, - * pool outer structures are declared with the pools. */ - -#define MVSig ((Sig)0x5193B999) /* SIGnature MV */ - -typedef struct MVStruct { /* MV pool outer structure */ - PoolStruct poolStruct; /* generic structure */ - MFSStruct blockPoolStruct; /* for managing block descriptors */ - MFSStruct spanPoolStruct; /* for managing span descriptors */ - Size extendBy; /* segment size to extend pool by */ - Size avgSize; /* client estimate of allocation size */ - Size maxSize; /* client estimate of maximum size */ - Size free; /* free space in pool */ - Size lost; /* */ - RingStruct spans; /* span chain */ - Sig sig; /* */ -} MVStruct; - - /* ReservoirStruct -- Reservoir structure * * .reservoir: See , . @@ -696,9 +672,40 @@ typedef struct FreelistStruct { } FreelistStruct; +/* MVFFStruct -- MVFF (Manual Variable First Fit) pool outer structure + * + * The signature is placed at the end, see + * + * + * The MVFF pool outer structure is declared here because it is the + * control pool structure which is inlined in the arena. Normally, + * pool outer structures are declared with the pools. + */ + +#define MVFFSig ((Sig)0x5193FFF9) /* SIGnature MVFF */ + +typedef struct MVFFStruct *MVFF; +typedef struct MVFFStruct { /* MVFF pool outer structure */ + PoolStruct poolStruct; /* generic structure */ + LocusPrefStruct locusPrefStruct; /* the preferences for allocation */ + Size extendBy; /* size to extend pool by */ + Size avgSize; /* client estimate of allocation size */ + double spare; /* spare space fraction, see MVFFReduce */ + MFSStruct cbsBlockPoolStruct; /* stores blocks for CBSs */ + CBSStruct totalCBSStruct; /* all memory allocated from the arena */ + CBSStruct freeCBSStruct; /* free memory (primary) */ + FreelistStruct flStruct; /* free memory (secondary, for emergencies) */ + FailoverStruct foStruct; /* free memory (fail-over mechanism) */ + Bool firstFit; /* as opposed to last fit */ + Bool slotHigh; /* prefers high part of large block */ + Sig sig; /* */ +} MVFFStruct; + + /* ArenaStruct -- generic arena * - * See . */ + * See . + */ #define ArenaSig ((Sig)0x519A6E4A) /* SIGnature ARENA */ @@ -709,7 +716,7 @@ typedef struct mps_arena_s { ArenaClass class; /* arena class structure */ Bool poolReady; /* */ - MVStruct controlPoolStruct; /* */ + MVFFStruct controlPoolStruct; /* */ ReservoirStruct reservoirStruct; /* */ diff --git a/mps/code/poolmv.c b/mps/code/poolmv.c index 19b3c2bb443..2190e03e198 100644 --- a/mps/code/poolmv.c +++ b/mps/code/poolmv.c @@ -4,9 +4,6 @@ * Copyright (c) 2001-2015 Ravenbrook Limited. See end of file for license. * Portions copyright (C) 2002 Global Graphics Software. * - * **** RESTRICTION: This pool may not allocate from the arena control - * pool, since it is used to implement that pool. - * * An observation: Freeing memory introduces more information * into the system than allocating it. This causes the problem * described in note 2. @@ -34,6 +31,30 @@ SRCID(poolmv, "$Id$"); +/* MVStruct -- MV (Manual Variable) pool outer structure + * + * .mv: See , . + * + * The signature is placed at the end, see + * + */ + +#define MVSig ((Sig)0x5193B999) /* SIGnature MV */ + +typedef struct MVStruct { /* MV pool outer structure */ + PoolStruct poolStruct; /* generic structure */ + MFSStruct blockPoolStruct; /* for managing block descriptors */ + MFSStruct spanPoolStruct; /* for managing span descriptors */ + Size extendBy; /* segment size to extend pool by */ + Size avgSize; /* client estimate of allocation size */ + Size maxSize; /* client estimate of maximum size */ + Size free; /* free space in pool */ + Size lost; /* */ + RingStruct spans; /* span chain */ + Sig sig; /* */ +} MVStruct; + + #define mvBlockPool(mv) MFSPool(&(mv)->blockPoolStruct) #define mvSpanPool(mv) MFSPool(&(mv)->spanPoolStruct) diff --git a/mps/code/poolmv.h b/mps/code/poolmv.h index 01c5b9ebd73..5229726583e 100644 --- a/mps/code/poolmv.h +++ b/mps/code/poolmv.h @@ -4,6 +4,9 @@ * Copyright (c) 2001-2014 Ravenbrook Limited. See end of file for license. * Portions copyright (C) 2002 Global Graphics Software. * + * FIXME: This header is no longer necessary since MV is no longer + * used internally. + * * .purpose: This is the interface to the manual-variable pool class. * * .mv: Manual-variable pools manage variably-sized blocks of memory diff --git a/mps/code/poolmvff.c b/mps/code/poolmvff.c index 22b6d004f68..cc7b59fe6a6 100644 --- a/mps/code/poolmvff.c +++ b/mps/code/poolmvff.c @@ -4,6 +4,9 @@ * Copyright (c) 2001-2014 Ravenbrook Limited. See end of file for license. * Portions copyright (C) 2002 Global Graphics Software. * + * **** RESTRICTION: This pool may not allocate from the arena control + * pool, since it is used to implement that pool. + * * .purpose: This is a pool class for manually managed objects of * variable size where address-ordered first fit is an appropriate * policy. Provision is made to allocate in reverse. @@ -24,6 +27,7 @@ #include "freelist.h" #include "mpm.h" #include "mpscmvff.h" +#include "poolmvff.h" #include "mpscmfs.h" #include "poolmfs.h" @@ -33,35 +37,10 @@ SRCID(poolmvff, "$Id$"); /* Would go in poolmvff.h if the class had any MPS-internal clients. */ extern PoolClass PoolClassMVFF(void); - -/* MVFFStruct -- MVFF (Manual Variable First Fit) pool outer structure - * - * The signature is placed at the end, see - * - */ - -#define MVFFSig ((Sig)0x5193FFF9) /* SIGnature MVFF */ - -typedef struct MVFFStruct *MVFF; -typedef struct MVFFStruct { /* MVFF pool outer structure */ - PoolStruct poolStruct; /* generic structure */ - LocusPrefStruct locusPrefStruct; /* the preferences for allocation */ - Size extendBy; /* size to extend pool by */ - Size avgSize; /* client estimate of allocation size */ - double spare; /* spare space fraction, see MVFFReduce */ - MFSStruct cbsBlockPoolStruct; /* stores blocks for CBSs */ - CBSStruct totalCBSStruct; /* all memory allocated from the arena */ - CBSStruct freeCBSStruct; /* free memory (primary) */ - FreelistStruct flStruct; /* free memory (secondary, for emergencies) */ - FailoverStruct foStruct; /* free memory (fail-over mechanism) */ - Bool firstFit; /* as opposed to last fit */ - Bool slotHigh; /* prefers high part of large block */ - Sig sig; /* */ -} MVFFStruct; - +/* Note: MVFFStruct is declared in mpmst.h rather than here because it + is the control pool and is inlined in the arena globals. */ #define PoolMVFF(pool) PARENT(MVFFStruct, poolStruct, pool) -#define MVFFPool(mvff) (&(mvff)->poolStruct) #define MVFFTotalLand(mvff) CBSLand(&(mvff)->totalCBSStruct) #define MVFFFreePrimary(mvff) CBSLand(&(mvff)->freeCBSStruct) #define MVFFFreeSecondary(mvff) FreelistLand(&(mvff)->flStruct) @@ -69,8 +48,6 @@ typedef struct MVFFStruct { /* MVFF pool outer structure */ #define MVFFLocusPref(mvff) (&(mvff)->locusPrefStruct) #define MVFFBlockPool(mvff) MFSPool(&(mvff)->cbsBlockPoolStruct) -static Bool MVFFCheck(MVFF mvff); - /* MVFFDebug -- MVFFDebug class */ @@ -777,8 +754,7 @@ mps_pool_class_t mps_class_mvff_debug(void) /* MVFFCheck -- check the consistency of an MVFF structure */ -ATTRIBUTE_UNUSED -static Bool MVFFCheck(MVFF mvff) +Bool MVFFCheck(MVFF mvff) { CHECKS(MVFF, mvff); CHECKD(Pool, MVFFPool(mvff)); diff --git a/mps/code/poolmvff.h b/mps/code/poolmvff.h new file mode 100644 index 00000000000..c823a4587c7 --- /dev/null +++ b/mps/code/poolmvff.h @@ -0,0 +1,72 @@ +/* poolmvff.h: First Fit Manual Variable Pool + * + * $Id$ + * Copyright (c) 2001-2014 Ravenbrook Limited. See end of file for license. + * Portions copyright (C) 2002 Global Graphics Software. + * + * .purpose: This is a pool class for manually managed objects of + * variable size where address-ordered first fit is an appropriate + * policy. Provision is made to allocate in reverse. + * + * .design: See + */ + +#ifndef poolmvff_h +#define poolmvff_h + + +#include "mpmtypes.h" +#include "mpscmvff.h" + +typedef struct MVFFStruct *MVFF; + +extern PoolClass PoolClassMVFF(void); + +extern Bool MVFFCheck(MVFF mvff); + +#define MVFFPool(mvff) (&(mvff)->poolStruct) + + +#endif /* poolmvff_h */ + + +/* C. COPYRIGHT AND LICENSE + * + * Copyright (C) 2001-2014 Ravenbrook Limited . + * All rights reserved. This is an open source license. Contact + * Ravenbrook for commercial licensing options. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. Redistributions in any form must be accompanied by information on how + * to obtain complete source code for this software and any accompanying + * software that uses this software. The source code must either be + * included in the distribution or be available for no more than the cost + * of distribution plus a nominal fee, and must be freely redistributable + * under reasonable conditions. For an executable file, complete source + * code means the source code for all modules it contains. It does not + * include source code for modules or files that typically accompany the + * major components of the operating system on which the executable file + * runs. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE, OR NON-INFRINGEMENT, ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */