On Sun, Oct 25, 2009 at 4:05 PM, Robert Klemme
<shortcutter / googlemail.com> wrote:
>> It's also interesting to note that even maintaining the contract of
>> object_id being unique is hard. On the JVM, for example, it is not
>> possible to get a unique numeric id or pointer for a given object
>> unless you manage a weak map of objects on your own...
>
> I believe there is an alternative solution which comes at the cost of the
> memory overhead for every object: place the id in the instance and use a
> central AtomicLong for "generating" ids. You also save the overheadf map
> maintenance which would be a central synchronization point.

Yes, that may be too high a cost for us to pay. On 32/64-bit JVMs,
adding another field would cost 4 or 8 bytes per object. Stuffing it
into the instance variable table would force ivar tables to be created
when object_id is called, which comes with a base cost of 2 words (4
or 8-byte) plus the word for the reference to a Fixnum object (or 4-8
bytes for a reference to an int or long). It's too high to put on all
Objects, especially if identityHashcode is unique enough.

- Charlie