From 791286acfac811bc6c174b3f35f7a444885480c4 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Fri, 10 Jan 2020 16:11:11 +0100 Subject: [PATCH] kernel: make MarkAllSubBagsDefault private, use in Julia GC 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. --- src/bags.inc | 5 ----- src/gasman.c | 29 +++++++++++++++++------------ src/gasman.h | 6 +++++- src/julia_gc.c | 20 +++++++++++++++++++- 4 files changed, 41 insertions(+), 19 deletions(-) diff --git a/src/bags.inc b/src/bags.inc index a7aee8478c..0cbb8467fe 100644 --- a/src/bags.inc +++ b/src/bags.inc @@ -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)); -} diff --git a/src/gasman.c b/src/gasman.c index ffa0cf9efb..1f69075c90 100644 --- a/src/gasman.c +++ b/src/gasman.c @@ -552,21 +552,26 @@ void InitSweepFuncBags ( } +/**************************************************************************** +** +*F MarkAllSubBagsDefault() . . . 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(,) . . . . . install marking function -*F MarkNoSubBags() . . . . . . . . marking function that marks nothing -*F MarkOneSubBags() . . . . . . marking function that marks one subbag -*F MarkTwoSubBags() . . . . . . marking function that marks two subbags -*F MarkThreeSubBags() . . . . marking function that marks three subbags -*F MarkFourSubBags() . . . . marking function that marks four subbags -*F MarkAllSubBags() . . . . . . 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 ]; diff --git a/src/gasman.h b/src/gasman.h index 222b0600ca..202736d6dd 100644 --- a/src/gasman.h +++ b/src/gasman.h @@ -693,10 +693,14 @@ void MarkFourSubBags(Bag bag); */ void MarkAllSubBags(Bag bag); -void MarkAllSubBagsDefault(Bag); +/**************************************************************************** +** +*F MarkAllButFirstSubBags() . . . . marks all subbags except the first +*/ void MarkAllButFirstSubBags(Bag bag); + /**************************************************************************** ** *F MarkBag() . . . . . . . . . . . . . . . . . . . mark a bag as live diff --git a/src/julia_gc.c b/src/julia_gc.c index 2710a3f479..e298c8d024 100644 --- a/src/julia_gc.c +++ b/src/julia_gc.c @@ -278,11 +278,29 @@ static void * AllocateBagMemory(UInt type, UInt size) return result; } + +/**************************************************************************** +** +*F MarkAllSubBagsDefault() . . . 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; } @@ -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()`.