Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kernel: refactor GASMAN's CollectBags some more #3812

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 40 additions & 43 deletions src/gasman.c
Original file line number Diff line number Diff line change
Expand Up @@ -1799,8 +1799,6 @@ static void GenStackFuncBags(void)
#endif
}

static UInt FullBags;

/* These are used to overwrite masterpointers which may still be
linked from weak pointer objects but whose bag bodies have been
collected. Two values are used so that old masterpointers of this
Expand All @@ -1812,7 +1810,7 @@ to ensure that IsWeakDeadBag works correctly.
static Bag * NewWeakDeadBagMarker = (Bag *)(1000*sizeof(Bag) + 1);
static Bag * OldWeakDeadBagMarker = (Bag *)(1001*sizeof(Bag) + 1);

static UInt CollectBags_Mark(void)
static UInt CollectBags_Mark(UInt FullBags)
{
Bag first; /* first bag on a linked list */
UInt nrLiveBags; /* number of live new bags */
Expand Down Expand Up @@ -1913,7 +1911,7 @@ static UInt CollectBags_Mark(void)
return nrLiveBags;
}

static UInt CollectBags_Sweep(void)
static UInt CollectBags_Sweep(UInt FullBags)
{
Bag * dst; /* destination in sweeping */
Bag * src; /* source in sweeping */
Expand Down Expand Up @@ -2070,7 +2068,7 @@ static UInt CollectBags_Sweep(void)
return nrDeadBags + nrHalfDeadBags;
}

static Int CollectBags_Check(UInt size, UInt nrBags)
static Int CollectBags_Check(UInt size, UInt FullBags, UInt nrBags)
{
UInt done; /* do we have to make a full gc */
Bag * p; /* loop variable */
Expand Down Expand Up @@ -2223,7 +2221,6 @@ UInt CollectBags (
UInt size,
UInt full )
{
Bag first; /* first bag on a linked list */
UInt nrBags; /* number of new bags */
UInt done; /* do we have to make a full gc */
UInt i; /* loop variable */
Expand All @@ -2240,50 +2237,50 @@ UInt CollectBags (
for (i = 0; i < CollectFuncBags.nrBefore; ++i)
CollectFuncBags.before[i]();

/* copy 'full' into a global variable, to avoid warning from GNU C */
FullBags = full;

/* do we want to make a full garbage collection? */
again:
if ( FullBags ) {

/* then every bag is considered to be a young bag */
YoungBags = OldBags;
NrLiveBags = 0;
SizeLiveBags = 0;

/* empty the list of changed old bags */
while ( ChangedBags != 0 ) {
first = ChangedBags;
ChangedBags = LINK_BAG(first);
LINK_BAG(first) = first;
do {
if (full) {

// then every bag is considered to be a young bag
YoungBags = OldBags;
NrLiveBags = 0;
SizeLiveBags = 0;

// empty the list of changed old bags
while ( ChangedBags != 0 ) {
Bag first = ChangedBags;
ChangedBags = LINK_BAG(first);
LINK_BAG(first) = first;
}

// Also time to change the tag for dead children of weak pointer
// objects. After this collection, there can be no more weak pointer
// objects pointing to anything with OldWeakDeadBagMarker in it.
SWAP(Bag *, OldWeakDeadBagMarker, NewWeakDeadBagMarker);
}

// Also time to change the tag for dead children of weak pointer
// objects. After this collection, there can be no more weak pointer
// objects pointing to anything with OldWeakDeadBagMarker in it.
SWAP(Bag *, OldWeakDeadBagMarker, NewWeakDeadBagMarker);
}
// information at the beginning of garbage collections
SyMsgsBags(full, 0, 0);

/* information at the beginning of garbage collections */
SyMsgsBags(FullBags, 0, 0);
// mark phase
nrBags = CollectBags_Mark(full);

/* * * * * * * * * * * * * * * mark phase * * * * * * * * * * * * * * */
nrBags = CollectBags_Mark();
// sweep phase
nrBags += CollectBags_Sweep(full);

/* * * * * * * * * * * * * * * sweep phase * * * * * * * * * * * * * * */
nrBags += CollectBags_Sweep();
// check phase
done = CollectBags_Check(size, full, nrBags);

/* * * * * * * * * * * * * * * check phase * * * * * * * * * * * * * * */
done = CollectBags_Check(size, nrBags);
if (done == 2)
return 0;
// the variable done can take on several values:
// 0: not yet finished, try again with a full collection
// 1: finished successfully to allocate the request memory
// 2: giving up, we are out of memory

// if we are not done, then try again
if ( ! done ) {
FullBags = 1;
goto again;
}
// if there is another iteration of this loop, the we should perform a
// full collection
full = 1;

} while (!done);

// call the after functions (if any)
for (i = 0; i < CollectFuncBags.nrAfter; ++i)
Expand All @@ -2302,7 +2299,7 @@ UInt CollectBags (

GAP_ASSERT(SanityCheckGasmanPointers());

return 1;
return done != 2;
}


Expand Down