diff --git a/mps/code/comm.gmk b/mps/code/comm.gmk index 86375096643..10bd1524405 100644 --- a/mps/code/comm.gmk +++ b/mps/code/comm.gmk @@ -229,8 +229,8 @@ LIB_TARGETS=mps.a mpsplan.a AUTO_TEST_TARGETS=abqtest amcss amcsshe amcssth amsss amssshe apss \ arenacv awlut awluthe btcv exposet0 expt825 fbmtest finalcv \ - finaltest lockcov locv messtest mpmss mpsicv mv2test poolncv qs \ - sacss segsmss steptest walkt0 zmess + finaltest fotest lockcov locv messtest mpmss mpsicv mv2test \ + poolncv qs sacss segsmss steptest walkt0 zmess # If it is not runnable as an automated test case, but is buildable, # add it to OTHER_TEST_TARGETS with a note. @@ -417,6 +417,9 @@ $(PFM)/$(VARIETY)/mpsicv: $(PFM)/$(VARIETY)/mpsicv.o \ $(PFM)/$(VARIETY)/mv2test: $(PFM)/$(VARIETY)/mv2test.o \ $(TESTLIBOBJ) $(PFM)/$(VARIETY)/mps.a +$(PFM)/$(VARIETY)/mvfftest: $(PFM)/$(VARIETY)/mvfftest.o \ + $(TESTLIBOBJ) $(PFM)/$(VARIETY)/mps.a + $(PFM)/$(VARIETY)/poolncv: $(PFM)/$(VARIETY)/poolncv.o \ $(TESTLIBOBJ) $(PFM)/$(VARIETY)/mps.a diff --git a/mps/code/fotest.c b/mps/code/fotest.c new file mode 100644 index 00000000000..fbb0fadb213 --- /dev/null +++ b/mps/code/fotest.c @@ -0,0 +1,252 @@ +/* fotest.c: FAIL-OVER TEST + * + * $Id$ + * Copyright (c) 2001-2013 Ravenbrook Limited. See end of file for license. + * Portions copyright (C) 2002 Global Graphics Software. + * + * This tests fail-over behaviour in low memory situations. The MVFF + * and MVT pool classes normally maintain their list of free blocks in + * a Coalescing Block Structure (CBS), but if the CBS cannot handle a + * request due to running out of memory, they fall back to a Freelist + * (which has zero memory overhead, at some cost in performance). + * + * This is a white box test: it patches the class of the CBS's + * internal block pool (MFS) with a pointer to a dummy class whose + * alloc() method always returns ResMEMORY. + */ + + +#include "mpscmvff.h" +#include "mpscmvt.h" +#include "mpsavm.h" + +#include "testlib.h" + +#include "cbs.h" +#include "mpm.h" +#include "mpmst.h" +#include "mpmtypes.h" +#include "poolmfs.h" + +#include + + +#define testArenaSIZE ((((size_t)3)<<24) - 4) +#define testSetSIZE 2000 +#define testLOOPS 10 + + +/* "OOM" pool class -- dummy alloc/free pool class whose alloc() + * method always returns ResMEMORY */ + +static Res OOMAlloc(Addr *pReturn, Pool pool, Size size, + Bool withReservoirPermit) +{ + UNUSED(pReturn); + UNUSED(pool); + UNUSED(size); + UNUSED(withReservoirPermit); + return ResMEMORY; +} + +extern PoolClass PoolClassOOM(void); +DEFINE_POOL_CLASS(OOMPoolClass, this) +{ + INHERIT_CLASS(this, AbstractAllocFreePoolClass); + this->alloc = OOMAlloc; +} + + +/* make -- allocate one object */ + +static mps_res_t make(mps_addr_t *p, mps_ap_t ap, size_t size) +{ + mps_res_t res; + + do { + MPS_RESERVE_BLOCK(res, *p, ap, size); + if(res != MPS_RES_OK) + return res; + } while(!mps_commit(ap, *p, size)); + + return MPS_RES_OK; +} + + +/* set_oom -- set blockPool of CBS to OOM or MFS according to argument. */ + +static void set_oom(CBS cbs, int oom) +{ + cbs->blockPool->class = oom ? EnsureOOMPoolClass() : PoolClassMFS(); +} + + +/* stress -- create a pool of the requested type and allocate in it */ + +static mps_res_t stress(size_t (*size)(unsigned long i), mps_pool_t pool, CBS cbs) +{ + mps_res_t res = MPS_RES_OK; + mps_ap_t ap; + unsigned long i, k; + int *ps[testSetSIZE]; + size_t ss[testSetSIZE]; + + die(mps_ap_create(&ap, pool, mps_rank_exact()), "BufferCreate"); + + /* allocate a load of objects */ + for (i=0; i= sizeof(ps[i])) + *ps[i] = 1; /* Write something, so it gets swap. */ + } + + for (k=0; k (b)) ? (a) : (b)) + +#define alignUp(w, a) (((w) + (a) - 1) & ~((size_t)(a) - 1)) + + +/* randomSizeAligned -- produce sizes both large and small, + * aligned by platform alignment */ + +static size_t randomSizeAligned(unsigned long i) +{ + size_t maxSize = 2 * 160 * 0x2000; + /* Reduce by a factor of 2 every 10 cycles. Total allocation about 40 MB. */ + return alignUp(rnd() % max((maxSize >> (i / 10)), 2) + 1, MPS_PF_ALIGN); +} + + +int main(int argc, char *argv[]) +{ + mps_arena_t arena; + mps_pool_t pool; + + randomize(argc, argv); + mps_lib_assert_fail_install(assert_die); + + die(mps_arena_create(&arena, mps_arena_class_vm(), testArenaSIZE), + "mps_arena_create"); + MPS_ARGS_BEGIN(args) { + MPS_ARGS_ADD(args, MPS_KEY_EXTEND_BY, (64 + rnd() % 64) * 1024); + MPS_ARGS_ADD(args, MPS_KEY_MEAN_SIZE, (1 + rnd() % 8) * 8); + MPS_ARGS_ADD(args, MPS_KEY_ALIGN, MPS_PF_ALIGN); + MPS_ARGS_ADD(args, MPS_KEY_MVFF_ARENA_HIGH, rnd() % 2); + MPS_ARGS_ADD(args, MPS_KEY_MVFF_SLOT_HIGH, rnd() % 2); + MPS_ARGS_ADD(args, MPS_KEY_MVFF_FIRST_FIT, rnd() % 2); + MPS_ARGS_DONE(args); + die(mps_pool_create_k(&pool, arena, mps_class_mvff(), args), "create MVFF"); + } MPS_ARGS_END(args); + { + extern CBS _mps_mvff_cbs(mps_pool_t); + CBS cbs = _mps_mvff_cbs(pool); + die(stress(randomSizeAligned, pool, cbs), "stress MVFF"); + } + mps_pool_destroy(pool); + mps_arena_destroy(arena); + + die(mps_arena_create(&arena, mps_arena_class_vm(), testArenaSIZE), + "mps_arena_create"); + MPS_ARGS_BEGIN(args) { + MPS_ARGS_ADD(args, MPS_KEY_MIN_SIZE, (1 + rnd() % 4) * 4); + MPS_ARGS_ADD(args, MPS_KEY_MEAN_SIZE, (1 + rnd() % 8) * 16); + MPS_ARGS_ADD(args, MPS_KEY_MAX_SIZE, (1 + rnd() % 4) * 1024); + MPS_ARGS_ADD(args, MPS_KEY_MVT_RESERVE_DEPTH, (1 + rnd() % 64) * 16); + MPS_ARGS_ADD(args, MPS_KEY_MVT_FRAG_LIMIT, (rnd() % 101) / 100.0); + MPS_ARGS_DONE(args); + die(mps_pool_create_k(&pool, arena, mps_class_mvt(), args), "create MVFF"); + } MPS_ARGS_END(args); + if (0) { + extern CBS _mps_mvt_cbs(mps_pool_t); + CBS cbs = _mps_mvt_cbs(pool); + die(stress(randomSizeAligned, pool, cbs), "stress MVT"); + } + mps_pool_destroy(pool); + mps_arena_destroy(arena); + + printf("%s: Conclusion: Failed to find any defects.\n", argv[0]); + return 0; +} + + +/* C. COPYRIGHT AND LICENSE + * + * Copyright (c) 2001-2013 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. + */ diff --git a/mps/code/mps.xcodeproj/project.pbxproj b/mps/code/mps.xcodeproj/project.pbxproj index d357065f07b..0706972f3b5 100644 --- a/mps/code/mps.xcodeproj/project.pbxproj +++ b/mps/code/mps.xcodeproj/project.pbxproj @@ -44,6 +44,7 @@ 3114A65B156E95B4001E0AA3 /* PBXTargetDependency */, 3114A5CC156E932C001E0AA3 /* PBXTargetDependency */, 3114A5EA156E93C4001E0AA3 /* PBXTargetDependency */, + 224CC79D175E187C002FF81B /* PBXTargetDependency */, 31D60034156D3D5A00337B26 /* PBXTargetDependency */, 3114A5A0156E915A001E0AA3 /* PBXTargetDependency */, 3114A6A7156E9739001E0AA3 /* PBXTargetDependency */, @@ -69,6 +70,10 @@ /* End PBXAggregateTarget section */ /* Begin PBXBuildFile section */ + 224CC791175E1821002FF81B /* testlib.c in Sources */ = {isa = PBXBuildFile; fileRef = 31EEAC9E156AB73400714D05 /* testlib.c */; }; + 224CC793175E1821002FF81B /* libmps.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 31EEABFB156AAF9D00714D05 /* libmps.a */; }; + 224CC79F175E321C002FF81B /* mv2test.c in Sources */ = {isa = PBXBuildFile; fileRef = 3114A686156E9674001E0AA3 /* mv2test.c */; }; + 224CC7A0175E322C002FF81B /* fotest.c in Sources */ = {isa = PBXBuildFile; fileRef = 224CC79E175E3202002FF81B /* fotest.c */; }; 2291A5B1175CAB2F001D4920 /* fmtdy.c in Sources */ = {isa = PBXBuildFile; fileRef = 3124CAC6156BE48D00753214 /* fmtdy.c */; }; 2291A5B2175CAB2F001D4920 /* fmtdytst.c in Sources */ = {isa = PBXBuildFile; fileRef = 3124CAC7156BE48D00753214 /* fmtdytst.c */; }; 2291A5B3175CAB2F001D4920 /* fmthe.c in Sources */ = {isa = PBXBuildFile; fileRef = 3124CAE4156BE6D500753214 /* fmthe.c */; }; @@ -165,7 +170,6 @@ 3114A670156E95F2001E0AA3 /* libmps.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 31EEABFB156AAF9D00714D05 /* libmps.a */; }; 3114A672156E95F6001E0AA3 /* testlib.c in Sources */ = {isa = PBXBuildFile; fileRef = 31EEAC9E156AB73400714D05 /* testlib.c */; }; 3114A673156E95F6001E0AA3 /* libmps.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 31EEABFB156AAF9D00714D05 /* libmps.a */; }; - 3114A687156E9674001E0AA3 /* mv2test.c in Sources */ = {isa = PBXBuildFile; fileRef = 3114A686156E9674001E0AA3 /* mv2test.c */; }; 3114A688156E967C001E0AA3 /* testlib.c in Sources */ = {isa = PBXBuildFile; fileRef = 31EEAC9E156AB73400714D05 /* testlib.c */; }; 3114A6A1156E9729001E0AA3 /* messtest.c in Sources */ = {isa = PBXBuildFile; fileRef = 3114A69F156E9725001E0AA3 /* messtest.c */; }; 3114A6A2156E972D001E0AA3 /* testlib.c in Sources */ = {isa = PBXBuildFile; fileRef = 31EEAC9E156AB73400714D05 /* testlib.c */; }; @@ -242,6 +246,20 @@ /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ + 224CC78E175E1821002FF81B /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 31EEABDA156AAE9E00714D05 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 31EEABFA156AAF9D00714D05; + remoteInfo = mps; + }; + 224CC79C175E187C002FF81B /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 31EEABDA156AAE9E00714D05 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 224CC78C175E1821002FF81B; + remoteInfo = mvfftest; + }; 2275798816C5422900B662B0 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 31EEABDA156AAE9E00714D05 /* Project object */; @@ -749,6 +767,15 @@ /* End PBXContainerItemProxy section */ /* Begin PBXCopyFilesBuildPhase section */ + 224CC794175E1821002FF81B /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = /usr/share/man/man1/; + dstSubfolderSpec = 0; + files = ( + ); + runOnlyForDeploymentPostprocessing = 1; + }; 2291A5B8175CAB2F001D4920 /* CopyFiles */ = { isa = PBXCopyFilesBuildPhase; buildActionMask = 2147483647; @@ -1076,6 +1103,8 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 224CC799175E1821002FF81B /* fotest */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "fotest"; sourceTree = BUILT_PRODUCTS_DIR; }; + 224CC79E175E3202002FF81B /* fotest.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = fotest.c; sourceTree = ""; }; 2291A5A8175CAA51001D4920 /* poolmv2.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = poolmv2.h; sourceTree = ""; }; 2291A5A9175CAA9B001D4920 /* awlutth.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = awlutth.c; sourceTree = ""; }; 2291A5AA175CAA9B001D4920 /* exposet0.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = exposet0.c; sourceTree = ""; }; @@ -1127,7 +1156,7 @@ 3114A633156E94DB001E0AA3 /* abqtest */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = abqtest; sourceTree = BUILT_PRODUCTS_DIR; }; 3114A63D156E94EA001E0AA3 /* abqtest.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = abqtest.c; sourceTree = ""; }; 3114A645156E9525001E0AA3 /* abq.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = abq.c; sourceTree = ""; }; - 3114A64C156E9596001E0AA3 /* fbmtest */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; name = fbmtest; path = fbmtest; sourceTree = BUILT_PRODUCTS_DIR; }; + 3114A64C156E9596001E0AA3 /* fbmtest */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = fbmtest; sourceTree = BUILT_PRODUCTS_DIR; }; 3114A662156E95D9001E0AA3 /* btcv */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = btcv; sourceTree = BUILT_PRODUCTS_DIR; }; 3114A66C156E95EB001E0AA3 /* btcv.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = btcv.c; sourceTree = ""; }; 3114A67C156E9668001E0AA3 /* mv2test */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = mv2test; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -1278,6 +1307,14 @@ /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ + 224CC792175E1821002FF81B /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 224CC793175E1821002FF81B /* libmps.a in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 2291A5B6175CAB2F001D4920 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; @@ -1636,6 +1673,7 @@ 3124CAC7156BE48D00753214 /* fmtdytst.c */, 3124CAE4156BE6D500753214 /* fmthe.c */, 3124CACC156BE4C200753214 /* fmtno.c */, + 224CC79E175E3202002FF81B /* fotest.c */, 31D60036156D3E0200337B26 /* lockcov.c */, 3114A5A1156E9168001E0AA3 /* locv.c */, 3114A69F156E9725001E0AA3 /* messtest.c */, @@ -1736,6 +1774,7 @@ 2291A5BD175CAB2F001D4920 /* awlutth */, 2291A5D1175CAFCA001D4920 /* expt825 */, 2291A5E3175CB05F001D4920 /* exposet0 */, + 224CC799175E1821002FF81B /* fotest */, ); name = Products; sourceTree = ""; @@ -1898,6 +1937,24 @@ /* End PBXHeadersBuildPhase section */ /* Begin PBXNativeTarget section */ + 224CC78C175E1821002FF81B /* fotest */ = { + isa = PBXNativeTarget; + buildConfigurationList = 224CC795175E1821002FF81B /* Build configuration list for PBXNativeTarget "fotest" */; + buildPhases = ( + 224CC78F175E1821002FF81B /* Sources */, + 224CC792175E1821002FF81B /* Frameworks */, + 224CC794175E1821002FF81B /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + 224CC78D175E1821002FF81B /* PBXTargetDependency */, + ); + name = fotest; + productName = mv2test; + productReference = 224CC799175E1821002FF81B /* fotest */; + productType = "com.apple.product-type.tool"; + }; 2291A5AC175CAB2F001D4920 /* awlutth */ = { isa = PBXNativeTarget; buildConfigurationList = 2291A5B9175CAB2F001D4920 /* Build configuration list for PBXNativeTarget "awlutth" */; @@ -2601,6 +2658,7 @@ 2291A5C1175CAFCA001D4920 /* expt825 */, 3114A5BC156E9315001E0AA3 /* finalcv */, 3114A5D5156E93A0001E0AA3 /* finaltest */, + 224CC78C175E1821002FF81B /* fotest */, 31D60026156D3D3E00337B26 /* lockcov */, 3114A58F156E913C001E0AA3 /* locv */, 3114A694156E971B001E0AA3 /* messtest */, @@ -2636,12 +2694,21 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "# Not listed here:\n# awlutth -- fails (job003506).\n# bttest and teletest -- interactive and so cannot be run unattended.\n# zcoll -- takes too long to be useful as a regularly run smoke test.\nTESTCASES=\"abqtest amcss amcsshe amcssth amsss amssshe apss arenacv \\\n awlut awluthe btcv expt825 exposet0 fbmtest finalcv \\\n finaltest lockcov locv messtest mpmss mpsicv mv2test \\\n poolncv qs sacss segsmss steptest walkt0 zmess\"\n\n../tool/testrun.sh $(for TEST in $TESTCASES; do echo $TARGET_BUILD_DIR/$TEST; done)\n\n# Coverage\nif [ \"$CONFIGURATION\" == \"Debug\" ]; then\n (cd xc/$PROJECT.build/$CONFIGURATION/$PROJECT.build/Objects-normal/x86_64 &&\n gcov mps.c 2> /dev/null) | ../tool/gcovfmt.py\nfi"; + shellScript = "# Not listed here:\n# awlutth -- fails (job003506).\n# bttest and teletest -- interactive and so cannot be run unattended.\n# zcoll -- takes too long to be useful as a regularly run smoke test.\nTESTCASES=\"abqtest amcss amcsshe amcssth amsss amssshe apss arenacv \\\n awlut awluthe btcv expt825 exposet0 fbmtest finalcv \\\n finaltest fotest lockcov locv messtest mpmss mpsicv mv2test \\\n poolncv qs sacss segsmss steptest walkt0 zmess\"\n\n../tool/testrun.sh $(for TEST in $TESTCASES; do echo $TARGET_BUILD_DIR/$TEST; done)\n\n# Coverage\nif [ \"$CONFIGURATION\" == \"Debug\" ]; then\n (cd xc/$PROJECT.build/$CONFIGURATION/$PROJECT.build/Objects-normal/x86_64 &&\n gcov mps.c 2> /dev/null) | ../tool/gcovfmt.py\nfi"; showEnvVarsInLog = 0; }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ + 224CC78F175E1821002FF81B /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 224CC7A0175E322C002FF81B /* fotest.c in Sources */, + 224CC791175E1821002FF81B /* testlib.c in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 2291A5AF175CAB2F001D4920 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; @@ -2876,7 +2943,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 3114A687156E9674001E0AA3 /* mv2test.c in Sources */, + 224CC79F175E321C002FF81B /* mv2test.c in Sources */, 3114A688156E967C001E0AA3 /* testlib.c in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -3038,6 +3105,16 @@ /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ + 224CC78D175E1821002FF81B /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 31EEABFA156AAF9D00714D05 /* mps */; + targetProxy = 224CC78E175E1821002FF81B /* PBXContainerItemProxy */; + }; + 224CC79D175E187C002FF81B /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 224CC78C175E1821002FF81B /* fotest */; + targetProxy = 224CC79C175E187C002FF81B /* PBXContainerItemProxy */; + }; 2275798916C5422900B662B0 /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = 2D604B9B16514B1A003AAF46 /* mpseventtxt */; @@ -3401,6 +3478,33 @@ /* End PBXTargetDependency section */ /* Begin XCBuildConfiguration section */ + 224CC796175E1821002FF81B /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + GCC_GENERATE_TEST_COVERAGE_FILES = YES; + GCC_INSTRUMENT_PROGRAM_FLOW_ARCS = YES; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 224CC797175E1821002FF81B /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + GCC_GENERATE_TEST_COVERAGE_FILES = NO; + GCC_INSTRUMENT_PROGRAM_FLOW_ARCS = NO; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; + 224CC798175E1821002FF81B /* WE */ = { + isa = XCBuildConfiguration; + buildSettings = { + GCC_GENERATE_TEST_COVERAGE_FILES = NO; + GCC_INSTRUMENT_PROGRAM_FLOW_ARCS = NO; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = WE; + }; 2291A5BA175CAB2F001D4920 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { @@ -4607,6 +4711,16 @@ /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ + 224CC795175E1821002FF81B /* Build configuration list for PBXNativeTarget "fotest" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 224CC796175E1821002FF81B /* Debug */, + 224CC797175E1821002FF81B /* Release */, + 224CC798175E1821002FF81B /* WE */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; 2291A5B9175CAB2F001D4920 /* Build configuration list for PBXNativeTarget "awlutth" */ = { isa = XCConfigurationList; buildConfigurations = ( diff --git a/mps/code/poolmv2.c b/mps/code/poolmv2.c index bdcfd2a69ae..8818517d823 100644 --- a/mps/code/poolmv2.c +++ b/mps/code/poolmv2.c @@ -1258,6 +1258,22 @@ static Bool MVTCheckFit(Addr base, Addr limit, Size min, Arena arena) } +/* Return the CBS of an MVT pool for the benefit of fotest.c. */ + +extern CBS _mps_mvt_cbs(mps_pool_t); +CBS _mps_mvt_cbs(mps_pool_t mps_pool) { + Pool pool; + MVT mvt; + + pool = (Pool)mps_pool; + AVERT(Pool, pool); + mvt = Pool2MVT(pool); + AVERT(MVT, mvt); + + return MVTCBS(mvt); +} + + /* C. COPYRIGHT AND LICENSE * * Copyright (C) 2001-2002 Ravenbrook Limited . diff --git a/mps/code/poolmvff.c b/mps/code/poolmvff.c index b7e91874ca8..f4df4a4eec4 100644 --- a/mps/code/poolmvff.c +++ b/mps/code/poolmvff.c @@ -86,7 +86,7 @@ typedef MVFFDebugStruct *MVFFDebug; * coalesced range containing given range. Does not attempt to free * segments (see MVFFFreeSegs). */ -static void MVFFAddToFreeList(Addr *baseIO, Addr *limitIO, MVFF mvff) { +static Res MVFFAddToFreeList(Addr *baseIO, Addr *limitIO, MVFF mvff) { Res res; RangeStruct range, newRange; @@ -102,12 +102,13 @@ static void MVFFAddToFreeList(Addr *baseIO, Addr *limitIO, MVFF mvff) { res = FreelistInsert(&newRange, FreelistOfMVFF(mvff), &range); } - AVER(res == ResOK); - mvff->free += RangeSize(&range); - *baseIO = RangeBase(&newRange); - *limitIO = RangeLimit(&newRange); + if (res == ResOK) { + mvff->free += RangeSize(&range); + *baseIO = RangeBase(&newRange); + *limitIO = RangeLimit(&newRange); + } - return; + return res; } @@ -149,11 +150,6 @@ static void MVFFFreeSegs(MVFF mvff, Addr base, Addr limit) RangeStruct range, oldRange; RangeInit(&range, segBase, segLimit); - /* Free the segment first to give the CBS the best chance of - * being able to delete the range. */ - SegFree(seg); - mvff->total -= RangeSize(&range); - res = CBSDelete(&oldRange, CBSOfMVFF(mvff), &range); if (res == ResOK) { mvff->free -= RangeSize(&range); @@ -172,18 +168,29 @@ static void MVFFFreeSegs(MVFF mvff, Addr base, Addr limit) { Addr leftBase = RangeBase(&oldRange); Addr leftLimit = segBase; - MVFFAddToFreeList(&leftBase, &leftLimit, mvff); + res = MVFFAddToFreeList(&leftBase, &leftLimit, mvff); } AVER(RangeLimit(&oldRange) != segLimit); { Addr rightBase = segLimit; Addr rightLimit = RangeLimit(&oldRange); - MVFFAddToFreeList(&rightBase, &rightLimit, mvff); + res = MVFFAddToFreeList(&rightBase, &rightLimit, mvff); } + } else if (res == ResFAIL) { + /* Not found in the CBS: must be found in the Freelist. */ + res = FreelistDelete(&oldRange, FreelistOfMVFF(mvff), &range); + AVER(res == ResOK); + mvff->free -= RangeSize(&range); } AVER(res == ResOK); AVER(RangesNest(&oldRange, &range)); + + /* Can't free the segment earlier, because if it was on the + * Freelist rather than the CBS then it likely contains data + * that needs to be read in order to update the Freelist. */ + SegFree(seg); + mvff->total -= RangeSize(&range); } /* Avoid calling SegNext if the next segment would fail */ @@ -255,7 +262,8 @@ static Res MVFFAddSeg(Seg *segReturn, base = SegBase(seg); limit = AddrAdd(base, segSize); DebugPoolFreeSplat(pool, base, limit); - MVFFAddToFreeList(&base, &limit, mvff); + res = MVFFAddToFreeList(&base, &limit, mvff); + AVER(res == ResOK); AVER(base <= SegBase(seg)); if (mvff->minSegSize > segSize) mvff->minSegSize = segSize; @@ -367,6 +375,7 @@ static Res MVFFAlloc(Addr *aReturn, Pool pool, Size size, static void MVFFFree(Pool pool, Addr old, Size size) { + Res res; Addr base, limit; MVFF mvff; @@ -382,10 +391,12 @@ static void MVFFFree(Pool pool, Addr old, Size size) base = old; limit = AddrAdd(base, size); + res = MVFFAddToFreeList(&base, &limit, mvff); + AVER(res == ResOK); + if (res == ResOK) + MVFFFreeSegs(mvff, base, limit); - MVFFAddToFreeList(&base, &limit, mvff); - - MVFFFreeSegs(mvff, base, limit); + return; } @@ -450,6 +461,7 @@ static Res MVFFBufferFill(Addr *baseReturn, Addr *limitReturn, static void MVFFBufferEmpty(Pool pool, Buffer buffer, Addr base, Addr limit) { + Res res; MVFF mvff; AVERT(Pool, pool); @@ -462,8 +474,10 @@ static void MVFFBufferEmpty(Pool pool, Buffer buffer, if (base == limit) return; - MVFFAddToFreeList(&base, &limit, mvff); - MVFFFreeSegs(mvff, base, limit); + res = MVFFAddToFreeList(&base, &limit, mvff); + AVER(res == ResOK); + if (res == ResOK) + MVFFFreeSegs(mvff, base, limit); return; } @@ -788,6 +802,22 @@ static Bool MVFFCheck(MVFF mvff) } +/* Return the CBS of an MVFF pool for the benefit of fotest.c. */ + +extern CBS _mps_mvff_cbs(mps_pool_t); +CBS _mps_mvff_cbs(mps_pool_t mps_pool) { + Pool pool; + MVFF mvff; + + pool = (Pool)mps_pool; + AVERT(Pool, pool); + mvff = Pool2MVFF(pool); + AVERT(MVFF, mvff); + + return CBSOfMVFF(mvff); +} + + /* C. COPYRIGHT AND LICENSE * * Copyright (C) 2001-2002 Ravenbrook Limited .