From b3a3b0b8fc21d72ca4342c7befa8a9cfb7b4e3c1 Mon Sep 17 00:00:00 2001 From: Gareth Rees Date: Wed, 16 Apr 2014 10:24:26 +0100 Subject: [PATCH] Move cbsfindinzones so that diff is cleaner. Copied from Perforce Change: 185578 ServerID: perforce.ravenbrook.com --- mps/code/cbs.c | 139 ++++++++++++++++++++++++------------------------- 1 file changed, 69 insertions(+), 70 deletions(-) diff --git a/mps/code/cbs.c b/mps/code/cbs.c index 177388bc0cb..8531fa0673b 100644 --- a/mps/code/cbs.c +++ b/mps/code/cbs.c @@ -925,6 +925,75 @@ static Bool cbsTestTreeInZones(SplayTree splay, Tree tree, && ZoneSetInter(zonedBlock->zones, closure->zoneSet) != ZoneSetEMPTY; } +static Res cbsFindInZones(Range rangeReturn, Range oldRangeReturn, + Land land, Size size, + ZoneSet zoneSet, Bool high) +{ + CBS cbs; + Tree tree; + cbsTestNodeInZonesClosureStruct closure; + Res res; + LandFindMethod landFind; + SplayFindMethod splayFind; + + AVER(rangeReturn != NULL); + AVER(oldRangeReturn != NULL); + AVERT(Land, land); + cbs = cbsOfLand(land); + AVERT(CBS, cbs); + AVER(IsLandSubclass(cbsLand(cbs), CBSZonedLandClass)); + /* AVERT(ZoneSet, zoneSet); */ + AVER(BoolCheck(high)); + + landFind = high ? cbsFindLast : cbsFindFirst; + splayFind = high ? SplayFindLast : SplayFindFirst; + + if (zoneSet == ZoneSetEMPTY) + return ResFAIL; + if (zoneSet == ZoneSetUNIV) { + FindDelete fd = high ? FindDeleteHIGH : FindDeleteLOW; + if ((*landFind)(rangeReturn, oldRangeReturn, land, size, fd)) + return ResOK; + else + return ResFAIL; + } + if (ZoneSetIsSingle(zoneSet) && size > ArenaStripeSize(LandArena(land))) + return ResFAIL; + + /* It would be nice if there were a neat way to eliminate all runs of + zones in zoneSet too small for size.*/ + + closure.arena = LandArena(land); + closure.zoneSet = zoneSet; + closure.size = size; + closure.high = high; + if (splayFind(&tree, cbsSplay(cbs), + cbsTestNodeInZones, + cbsTestTreeInZones, + &closure, sizeof(closure))) { + CBSBlock block = cbsBlockOfTree(tree); + RangeStruct rangeStruct, oldRangeStruct; + + AVER(CBSBlockBase(block) <= closure.base); + AVER(AddrOffset(closure.base, closure.limit) >= size); + AVER(ZoneSetSub(ZoneSetOfRange(LandArena(land), closure.base, closure.limit), zoneSet)); + AVER(closure.limit <= CBSBlockLimit(block)); + + if (!high) + RangeInit(&rangeStruct, closure.base, AddrAdd(closure.base, size)); + else + RangeInit(&rangeStruct, AddrSub(closure.limit, size), closure.limit); + res = cbsDelete(&oldRangeStruct, land, &rangeStruct); + if (res == ResOK) { /* enough memory to split block */ + RangeCopy(rangeReturn, &rangeStruct); + RangeCopy(oldRangeReturn, &oldRangeStruct); + } + } else + res = ResFAIL; + + return res; +} + /* cbsFindLast -- find the last block of at least the given size */ @@ -1006,76 +1075,6 @@ static Bool cbsFindLargest(Range rangeReturn, Range oldRangeReturn, } -static Res cbsFindInZones(Range rangeReturn, Range oldRangeReturn, - Land land, Size size, - ZoneSet zoneSet, Bool high) -{ - CBS cbs; - Tree tree; - cbsTestNodeInZonesClosureStruct closure; - Res res; - LandFindMethod landFind; - SplayFindMethod splayFind; - - AVER(rangeReturn != NULL); - AVER(oldRangeReturn != NULL); - AVERT(Land, land); - cbs = cbsOfLand(land); - AVERT(CBS, cbs); - AVER(IsLandSubclass(cbsLand(cbs), CBSZonedLandClass)); - /* AVERT(ZoneSet, zoneSet); */ - AVER(BoolCheck(high)); - - landFind = high ? cbsFindLast : cbsFindFirst; - splayFind = high ? SplayFindLast : SplayFindFirst; - - if (zoneSet == ZoneSetEMPTY) - return ResFAIL; - if (zoneSet == ZoneSetUNIV) { - FindDelete fd = high ? FindDeleteHIGH : FindDeleteLOW; - if ((*landFind)(rangeReturn, oldRangeReturn, land, size, fd)) - return ResOK; - else - return ResFAIL; - } - if (ZoneSetIsSingle(zoneSet) && size > ArenaStripeSize(LandArena(land))) - return ResFAIL; - - /* It would be nice if there were a neat way to eliminate all runs of - zones in zoneSet too small for size.*/ - - closure.arena = LandArena(land); - closure.zoneSet = zoneSet; - closure.size = size; - closure.high = high; - if (splayFind(&tree, cbsSplay(cbs), - cbsTestNodeInZones, - cbsTestTreeInZones, - &closure, sizeof(closure))) { - CBSBlock block = cbsBlockOfTree(tree); - RangeStruct rangeStruct, oldRangeStruct; - - AVER(CBSBlockBase(block) <= closure.base); - AVER(AddrOffset(closure.base, closure.limit) >= size); - AVER(ZoneSetSub(ZoneSetOfRange(LandArena(land), closure.base, closure.limit), zoneSet)); - AVER(closure.limit <= CBSBlockLimit(block)); - - if (!high) - RangeInit(&rangeStruct, closure.base, AddrAdd(closure.base, size)); - else - RangeInit(&rangeStruct, AddrSub(closure.limit, size), closure.limit); - res = cbsDelete(&oldRangeStruct, land, &rangeStruct); - if (res == ResOK) { /* enough memory to split block */ - RangeCopy(rangeReturn, &rangeStruct); - RangeCopy(oldRangeReturn, &oldRangeStruct); - } - } else - res = ResFAIL; - - return res; -} - - /* cbsDescribe -- describe a CBS * * See .