Skip to content

Commit

Permalink
kernel: make MarkAllSubBagsDefault private, use in Julia GC
Browse files Browse the repository at this point in the history
MarkAllSubBagsDefault is an implementation detail of GASMAN (and
now also Julia GC), and should not be used by client code ever. As such,
it seems sensible to hide its implementation.

Also update/remove/add some comments.
  • Loading branch information
fingolfin authored and ChrisJefferson committed Jan 10, 2020
1 parent 1ab4dda commit 791286a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 19 deletions.
5 changes: 0 additions & 5 deletions src/bags.inc
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,3 @@ void MarkAllButFirstSubBags(Bag bag)
{
MarkArrayOfBags(CONST_PTR_BAG(bag) + 1, SIZE_BAG(bag) / sizeof(Bag) - 1);
}

void MarkAllSubBagsDefault(Bag bag)
{
MarkArrayOfBags(CONST_PTR_BAG(bag), SIZE_BAG(bag) / sizeof(Bag));
}
29 changes: 17 additions & 12 deletions src/gasman.c
Original file line number Diff line number Diff line change
Expand Up @@ -552,21 +552,26 @@ void InitSweepFuncBags (
}


/****************************************************************************
**
*F MarkAllSubBagsDefault(<bag>) . . . marking function that marks everything
**
** 'MarkAllSubBagsDefault' is the same as 'MarkAllSubBags' but is used as
** the initial default marking function. This allows to catch cases where
** 'InitMarkFuncBags' is called twice for the same type: the first time is
** accepted because the marking function is still 'MarkAllSubBagsDefault';
** the second time raises a warning, because a non-default marking function
** is being replaced.
*/
static void MarkAllSubBagsDefault(Bag bag)
{
MarkArrayOfBags(CONST_PTR_BAG(bag), SIZE_BAG(bag) / sizeof(Bag));
}


/****************************************************************************
**
*F InitMarkFuncBags(<type>,<mark-func>) . . . . . install marking function
*F MarkNoSubBags(<bag>) . . . . . . . . marking function that marks nothing
*F MarkOneSubBags(<bag>) . . . . . . marking function that marks one subbag
*F MarkTwoSubBags(<bag>) . . . . . . marking function that marks two subbags
*F MarkThreeSubBags(<bag>) . . . . marking function that marks three subbags
*F MarkFourSubBags(<bag>) . . . . marking function that marks four subbags
*F MarkAllSubBags(<bag>) . . . . . . marking function that marks everything
**
** 'InitMarkFuncBags', 'MarkNoSubBags', 'MarkOneSubBags', 'MarkTwoSubBags',
** and 'MarkAllSubBags' are really too simple for an explanation.
**
** 'MarkAllSubBagsDefault' is the same as 'MarkAllSubBags' but is only used
** by GASMAN as default. This will allow to catch type clashes.
*/

TNumMarkFuncBags TabMarkFuncBags [ NUM_TYPES ];
Expand Down
6 changes: 5 additions & 1 deletion src/gasman.h
Original file line number Diff line number Diff line change
Expand Up @@ -693,10 +693,14 @@ void MarkFourSubBags(Bag bag);
*/
void MarkAllSubBags(Bag bag);

void MarkAllSubBagsDefault(Bag);

/****************************************************************************
**
*F MarkAllButFirstSubBags(<bag>) . . . . marks all subbags except the first
*/
void MarkAllButFirstSubBags(Bag bag);


/****************************************************************************
**
*F MarkBag(<bag>) . . . . . . . . . . . . . . . . . . . mark a bag as live
Expand Down
20 changes: 19 additions & 1 deletion src/julia_gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,11 +278,29 @@ static void * AllocateBagMemory(UInt type, UInt size)
return result;
}


/****************************************************************************
**
*F MarkAllSubBagsDefault(<bag>) . . . marking function that marks everything
**
** 'MarkAllSubBagsDefault' is the same as 'MarkAllSubBags' but is used as
** the initial default marking function. This allows to catch cases where
** 'InitMarkFuncBags' is called twice for the same type: the first time is
** accepted because the marking function is still 'MarkAllSubBagsDefault';
** the second time raises a warning, because a non-default marking function
** is being replaced.
*/
static void MarkAllSubBagsDefault(Bag bag)
{
MarkArrayOfBags(CONST_PTR_BAG(bag), SIZE_BAG(bag) / sizeof(Bag));
}

TNumMarkFuncBags TabMarkFuncBags[NUM_TYPES];

void InitMarkFuncBags(UInt type, TNumMarkFuncBags mark_func)
{
// HOOK: set mark function for type `type`.
GAP_ASSERT(TabMarkFuncBags[type] == MarkAllSubBagsDefault);
TabMarkFuncBags[type] = mark_func;
}

Expand Down Expand Up @@ -714,7 +732,7 @@ void InitBags(UInt initial_size, Bag * stack_bottom, UInt stack_align)
// HOOK: initialization happens here.
GapStackBottom = stack_bottom;
for (UInt i = 0; i < NUM_TYPES; i++) {
TabMarkFuncBags[i] = MarkAllSubBags;
TabMarkFuncBags[i] = MarkAllSubBagsDefault;
}
// These callbacks need to be set before initialization so
// that we can track objects allocated during `jl_init()`.
Expand Down

0 comments on commit 791286a

Please sign in to comment.