Object ID's

Lars T Hansen lth at acm.org
Wed Mar 21 09:23:13 PDT 2007


On 3/21/07, Igor Bukanov <igor at mir2.org> wrote:
> I have a question about feasibility to implement intrinsic::hashcode
> (even with collisions) efficiently in an implementation with a copy GC
> collector. For me at seems that it would require to put an id in each
> and every object to ensure that the hashcode stays the same during the
>  lifetime of the object. Or there is some trick to avoid that?

Ole Agesen published a trick a few years back in TAPOS
(http://www.wiley.com/legacy/compbooks/object/index.html).  You return
the object's address when the hashcode is first obtained and set a bit
in the object header.  If the object survives a relocating collection
and the bit is set, a field is prefixed to the header that records the
original address.  So you need two free bits in the header in every
relocatable object, but that beats needing a full word.

You can also use a system-wide weak table that records objects that
have hash codes, I imagine, with rehashes following GC, and it's not
obvious this won't be efficient enough in practice (but it's not as
elegant).

--lars



More information about the Es4-discuss mailing list