Re: [Gc] weak maps and libgc
ivmai at mail.ru
Fri Oct 21 07:40:07 PDT 2011
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?
21 10 2011, 15:37 Andy Wingo <wingo at pobox.com>:
> 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:
> 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?
> Gc mailing list
> Gc at linux.hpl.hp.com
More information about the Gc