[Gc] finalization and GC ....

Basile Starynkevitch <[email protected]> Thu, 15 May 2014 14:01:49 +0200
Newsgroups gmane.comp.programming.garbage-collection.boehmgc
Message-ID <[email protected]>
Hello All,

My code is GPLv3 free software 
(available on https://github.com/bstarynk/melt-monitor but still in pre-alpha stage...), 
for Linux/Debian/x8664,
multi-threaded, using libonion (from https://github.com/davidmoreno/onion - 
you'll need the very latest commit since David Moreno has just merged a patch 
from me to make it Boehm GC friendly), and I am using the Boehm GC. My app has a web interface 
provided by libonion.

Indeed, having all threads (including the internal threads created by libonion)
created by GC_pthread_create is essential.

My system is persisting its data (on Sqlite3 database), conceptually the entire heap, 
but that is not my point today.

I have two kinds of GC data:

   immutable values (like boxed strings, boxed closures, boxed nodes, etc...)
   
   mutable items.
   
Items have each their own pthread mutex and access inside an item is protected by its mutex.

Items have also a UUID (16 random bytes, which are supposed to be unique).

I may need to fetch an item by its UUID. (If the item does not exist, getting a NULL pointer is ok).

So at item allocation, I register the item in some weak hash table. In file 
https://github.com/bstarynk/melt-monitor/blob/master/items.c line 323
I have a function mom_allocate_item_with_uuid which adds that item
into an hash table items_data which is allocated with GC_MALLOC_ATOMIC 
(but contains pointers which are invisible to Boehm GC).
The newly allocated item is registered with a finalizer. 
That finalizer, mom_finalize_item, is supposed to remove its entry 
from the global hash table items_data.

Is it the right way to code a weak hash table with Boehm's GC?

I have the impression that many items are not finalized, in other words that 
there 
is some memory leak. Do you have any advice on hunting such leaks?

Other question, does GC_gcollect () always do a full garbage collection, or 
will it decide to avoid the GC if, for instance, the heap is quite small. 
(My current heap has only a few hundred kilobytes).
Is there something to do to explicitly force a full garbage collection 
even if the heap is very small?

General tricks about debugging a multi-threaded app using Boehm's GC are welcome.

Regards.
-- 
Basile STARYNKEVITCH         http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mines, sont seulement les miennes} ***