RE: JavaMemoryModel: Finalization idioms

From: David Holmes (
Date: Sun May 01 2005 - 19:33:33 EDT


> My model was that in the ResourceManager code, both useA and useB
> end with something that enforces reachability of "this", i.e. the
> ResourceManager.

You have missed my point. It is not sufficient that the resource manager be
reachable during execution of its own methods useA and useB, it must also be
seen to be reachable during executing of the client code someMethod,
otherwise the resource manager could be finalized in between the calls to
the resource manager methods:

   void someMethod() {
     ResourceManager man = new ResourceManager();
         // man could be finalized here
     int result1 = man.useA();
         // or here
     int result2 = man.useB();
         // or here

Unless the system treats useA/useB as inlined and can see those internal
sync blocks then I don't see how those internal sync blocks will help. Now
if they *were* inlined then sure I can see that a sync block at the end of
useB would be indistinguishable from a sync block at the end of someMethod.
But is that the way it is supposed to work? Is the system supposed to be
able to see inside those called methods to determine reachability?

This seems horrednously complicated, both from the programmers perspective
and the systems. What kind of analysis would the system have to do to
determine that an object can be considered unreachable when only referenced
by a local? Why would they bother doing that analysis?

David Holmes

JavaMemoryModel mailing list -

This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:01:10 EDT