static Res MFSInit(Pool pool, Arena arena, PoolClass klass, ArgList args) { Size extendBy = MFS_EXTEND_BY_DEFAULT; Bool extendSelf = TRUE; Size unitSize; MFS mfs; ArgStruct arg; Res res; AVER(pool != NULL); AVERT(Arena, arena); AVERT(ArgList, args); UNUSED(klass); /* used for debug pools only */ ArgRequire(&arg, args, MPS_KEY_MFS_UNIT_SIZE); unitSize = arg.val.size; if (ArgPick(&arg, args, MPS_KEY_EXTEND_BY)) extendBy = arg.val.size; if (ArgPick(&arg, args, MFSExtendSelf)) extendSelf = arg.val.b; AVER(unitSize > 0); AVER(extendBy > 0); AVERT(Bool, extendSelf); res = NextMethod(Pool, MFSPool, init)(pool, arena, klass, args); if (res != ResOK) goto failNextInit; mfs = CouldBeA(MFSPool, pool); mfs->unroundedUnitSize = unitSize; if (unitSize < UNIT_MIN) unitSize = UNIT_MIN; unitSize = SizeAlignUp(unitSize, MPS_PF_ALIGN); if (extendBy < unitSize) extendBy = unitSize; extendBy = SizeArenaGrains(extendBy, arena); mfs->extendBy = extendBy; mfs->extendSelf = extendSelf; mfs->unitSize = unitSize; mfs->freeList = NULL; mfs->tractList = NULL; mfs->total = 0; mfs->free = 0; SetClassOfPoly(pool, CLASS(MFSPool)); mfs->sig = MFSSig; AVERC(MFS, mfs); EVENT5(PoolInitMFS, pool, arena, extendBy, BOOLOF(extendSelf), unitSize); return ResOK; failNextInit: AVER(res != ResOK); return res; }
static Res MFSInit(Pool pool, ArgList args) { Size extendBy = MFS_EXTEND_BY_DEFAULT; Bool extendSelf = TRUE; Size unitSize; MFS mfs; Arena arena; ArgStruct arg; AVER(pool != NULL); AVERT(ArgList, args); ArgRequire(&arg, args, MPS_KEY_MFS_UNIT_SIZE); unitSize = arg.val.size; if (ArgPick(&arg, args, MPS_KEY_EXTEND_BY)) extendBy = arg.val.size; else { if (extendBy < unitSize) extendBy = unitSize; } if (ArgPick(&arg, args, MFSExtendSelf)) extendSelf = arg.val.b; AVER(extendBy >= unitSize); AVERT(Bool, extendSelf); mfs = PoolPoolMFS(pool); arena = PoolArena(pool); mfs->unroundedUnitSize = unitSize; if (unitSize < UNIT_MIN) unitSize = UNIT_MIN; unitSize = SizeAlignUp(unitSize, MPS_PF_ALIGN); extendBy = SizeAlignUp(extendBy, ArenaAlign(arena)); mfs->extendBy = extendBy; mfs->extendSelf = extendSelf; mfs->unitSize = unitSize; mfs->freeList = NULL; mfs->tractList = NULL; mfs->sig = MFSSig; AVERT(MFS, mfs); EVENT5(PoolInitMFS, pool, arena, extendBy, BOOL(extendSelf), unitSize); return ResOK; }
static Res DebugPoolInit(Pool pool, ArgList args) { Res res; PoolDebugOptions options; PoolDebugMixin debug; TagInitMethod tagInit; Size tagSize; ArgStruct arg; AVERT(Pool, pool); /* TODO: Split this structure into separate keyword arguments, now that we can support them. */ ArgRequire(&arg, args, MPS_KEY_POOL_DEBUG_OPTIONS); options = (PoolDebugOptions)arg.val.pool_debug_options; AVERT(PoolDebugOptions, options); /* @@@@ Tag parameters should be taken from options, but tags have */ /* not been published yet. */ tagInit = NULL; tagSize = 0; res = SuperclassOfPool(pool)->init(pool, args); if (res != ResOK) return res; debug = DebugPoolDebugMixin(pool); AVER(debug != NULL); /* fencepost init */ /* @@@@ This parses a user argument, options, so it should really */ /* go through the MPS interface. The template needs to be copied */ /* into Addr memory, to avoid breaking <design/type/#addr.use>. */ debug->fenceSize = options->fenceSize; if (debug->fenceSize != 0) { if (debug->fenceSize % PoolAlignment(pool) != 0) { res = ResPARAM; goto alignFail; } /* Fenceposting turns on tagging */ if (tagInit == NULL) { tagSize = 0; tagInit = TagTrivInit; } debug->fenceTemplate = options->fenceTemplate; } /* free-checking init */ /* @@@@ This parses a user argument, options, so it should really */ /* go through the MPS interface. The template needs to be copied */ /* into Addr memory, to avoid breaking <design/type#addr.use>. */ debug->freeSize = options->freeSize; if (debug->freeSize != 0) { if (PoolAlignment(pool) % debug->freeSize != 0) { res = ResPARAM; goto alignFail; } debug->freeTemplate = options->freeTemplate; } /* tag init */ debug->tagInit = tagInit; if (debug->tagInit != NULL) { debug->tagSize = tagSize + sizeof(tagStruct) - 1; /* This pool has to be like the arena control pool: the blocks */ /* allocated must be accessible using void*. */ MPS_ARGS_BEGIN(pcArgs) { MPS_ARGS_ADD(pcArgs, MPS_KEY_EXTEND_BY, debug->tagSize); /* FIXME: Check this */ MPS_ARGS_ADD(pcArgs, MPS_KEY_MFS_UNIT_SIZE, debug->tagSize); MPS_ARGS_DONE(pcArgs); res = PoolCreate(&debug->tagPool, PoolArena(pool), PoolClassMFS(), pcArgs); } MPS_ARGS_END(pcArgs); if (res != ResOK) goto tagFail; debug->missingTags = 0; SplayTreeInit(&debug->index, TagComp, NULL); }