oop, Handle, and hash key

Peng Du imdupeng at gmail.com
Mon Mar 1 13:09:05 PST 2010


Hi, ramki

Thanks for your quick reply! You're right about what I want. weak global
JNI handle seems a good solution. I guess later I have to put some hooks
into GC to do the reclamation. Otherwise, I need a periodic thread to do
the housekeeping. 

In case I have further questions, I will post back. Thanks!


On Mon, 2010-03-01 at 12:58 -0800, Y. Srinivas Ramakrishna wrote:
> Hi Peng --
> 
> Peng Du wrote:
> > Hello, 
> > 
> > I need unique and persistent identifiers to Java objects as keys to a
> > hash table. However, I couldn't find an object_id kind routine. And I am
> > not sure if identity_hash() guarantees uniqueness. So, I figured I can
> > use the address of a Handle of an oop for this purpose, e.g. 
> > 
> > oop o;
> > ...
> > Handle h(o);
> > ...
> > hash.put(h->raw_value(), xx);
> > 
> > 
> > Considering there is no HandleMark around the code, does this work? If
> > yes, would GC reclaim the handle if the associated object (oop) dies? 
> 
> When would you release the handle? What you seem to need is
> basically a weak global JNI handle. JVM internal Handle's will
> not work in your case for the reasons you gave above -- you do
> not have a HandleMark, so the lifetime of your handle is determined
> by some unknown HandleMark in which your code is nesting above, and
> so your handle will be destructed at some unspecified point depending
> upon context. Worse, as long as your handle is in scope, the
> object being referred to will be kept alive so you'll see
> this as leaks in the java heap. I think (if i understood yr
> use correctly) that what you really need is a weak global JNI ref
> to use as the key into your hash table. And you'd need to periodically
> remove the tombstone entries for the dead and reclaimed oop's (the
> weak refs will not keep the oops alive which is exactly the
> behaviour i think you want?).
> 
> -- ramki
> 
> > 
> > 
> > Thanks
> > 
> > 
> > 
> 




More information about the hotspot-dev mailing list