Howto keep track of GC, without letting the monitored object die?

Tony Printezis Antonios.Printezis at sun.com
Wed Mar 25 13:52:33 PDT 2009


Clemens,

Clemens Eisserer wrote:
> Hi Tony,
>   
>> You can use WeakReferences. Have a look at this article:
>>
>> http://java.sun.com/developer/technicalArticles/javase/finalization/
>>
>> In particular, the An Alternative To Finalization section.
>>     
>
> I don't see how. In my example I rely on the behaviour that I can add
> a strong reference to the SharedObject when the finalizer runs,
> therefor letting it survive the GC.
>
> As far as I understand, with WeakReferences I could get a notification
> that the object was reclaimed but once I get the notification, the
> SharedObject as well as the monitorObject would both be gone already.
>   
This is correct.

So, I clearly misunderstood your example. Do you really want to notice 
when an object becomes unreachable and, if it is, retain it? Yikes. Can 
this object be found to be dead and then re-instated several times? If 
this is the case, then the finalization approach won't work (an object 
can only be finalized once; if it's re-instated and then dropped again, 
the second time it is just reclaimed). In fact, I don't know whether you 
can do what you want in Java; I can't think of a way to do it.

Other systems that I'm aware of that try to do something similar to what 
you're trying to do take a slightly different approach: they explicitly 
keep track of any references from remote node, say, R into each local 
node, say L, and this is what's keeping everything reachable from them 
live in node L. When one of those references is dropped, then node R has 
to notify node L that that reference was dropped, node L will remove it 
from its local list, and this is how objects reachable from that 
reference might be reclaimed.

Tony

-- 
---------------------------------------------------------------------
| Tony Printezis, Staff Engineer   | Sun Microsystems Inc.          |
|                                  | MS UBUR02-311                  |
| e-mail: tony.printezis at sun.com   | 35 Network Drive               |
| office: +1 781 442 0998 (x20998) | Burlington, MA 01803-2756, USA |
---------------------------------------------------------------------
e-mail client: Thunderbird (Linux)





More information about the hotspot-gc-dev mailing list