Re: [Gc] weak maps and libgc

Ivan Maidanski ivmai at mail.ru
Fri Oct 21 07:40:07 PDT 2011


Hi Andy,

I haven't implemented weak maps on top of bdwgc directly but I've implemented Java weakness model (Weak/Soft/Phantom/JNI_Weak) based only on this collector API (i.e., using only GC_register_finalizer_no_order (in java-finalization mode),  GC_malloc_atomic, GC_general_register_disappearing_link, GC_call_with_alloc_lock and GC_HIDE_POINTER). (Although, I can't say it is efficient as, e.g., I've to allocate and register a proxy object for a weak reference registered in a ReferenceQueue.)

And, taking into account that Java runtime has implementations of weak maps using Java references, I don't see immediately the problems of implementing a weak map (at least in terms of Java) w/o altering the current GC API.

Could you please summarize your past writings about the implementations difficulties?
Thanks.

Regards.

21 10 2011, 15:37 Andy Wingo <wingo at pobox.com>:
> Hello,
> 
> I and a few others have written in the past about the difficulties of
> implementing weak maps with libgc.  Properly implementing weak maps
> requires GC integration.  Currently I do terrible things with the pre-GC
> hook marking a flag that causes a vacuum procedure to run after GC.  I
> had not thought about the problem of cycles from values to keys in
> key-weak maps though:
> 
>   http://www.jucs.org/jucs_14_21/eliminating_cycles_in_weak/jucs_14_21_3481_3497_barros.pdf
> 
> To implement this sort of thing, you need tighter GC integration.  But
> providing those hooks limits the GC.  To avoid publicly exposing those
> hooks, it would be possible to incorporate a weak map or weak set
> implementation into libgc itself.  What do you think?
> 
> Andy
> --
> http://wingolog.org/
> _______________________________________________
> Gc mailing list
> Gc at linux.hpl.hp.com
> http://www.hpl.hp.com/hosted/linux/mail-archives/gc/
> 



More information about the Gc mailing list