Jochen Hoenicke wrote:
> 
> Another point is how to put pointers to native structures into a
> classfile.  Sun didn't solve it well.  If I understand the code in
> japhar's java/util/zip correctly sun used an int field to store the
> pointer and later changed it to long to support 64bit architectures.
> libgcj declares natives fields as "gnu.gcj.RawData", but this is not
> portable to other jvms, where the garbage collector doesn't know that
> this class is special.  My solution was to put the structure into a
> java byte array, which imposes a little overhead, but should be
> portable (and you get it freed automatically).

Classpath has been using a library called NSA, which Paul wrote IIRC,
that can be implemented either with native VM support if available
(which Japhar has) enabling the native data to actually be stored as
part of the object, or using a hash table based on the
System.identityHashCode of the object if not. I haven't heard about any
problems with this approach. Admittedly it's a little overhead if your
VM doesn't provide the support, but it's only a little and it doesn't
take much to add the support to a VM. Plus it's 100% portable.

Stuart.

Reply via email to