Re: JavaMemoryModel: Implementing KeepAlive

From: Hans Boehm ([email protected])
Date: Sat Apr 24 2004 - 01:58:52 EDT


Yes. That's one reason not to go with the weak interpretation.

I now think there are others. It's possible to break a program by writing
zero to a volatile variable that is always zero. I think this complicates
reasoning about programs without much benefit. We decided to go with the
strong interpretation in the end.

Hans

On Fri, 23 Apr 2004, Doron Rajwan wrote:

>
> Isn't this code totally broken with the weak volatile
> interpretation?
>
> Doron.
>
>
> --- Bill Pugh <[email protected]> wrote:
> > OK, here is a class that implements keepAlive:
> >
> > public class FinalizerHelp {
> > static volatile Object v;
> > public static void keepAlive(Object o) {
> > v = o;
> > v = null;
> > }
> > public static void getReadyToFinalize() {
> > Object o = v;
> > }
> > }
> >
> > The semantics we provided to ensure that finalizer
> > guardians would work
> > will also ensure that an object is still reachable
> > if we are going to
> > write a reference to that object into a global
> > variable.
> >
> > Because the write is a volatile write, preceding
> > memory accesses can't
> > be reordered with the call to keepAlive.
> >
> > The one point of ugliness here is that each
> > finalizer should call
> > FinalizerHelp.getReadyToFinalize().
> >
> > Bill
> >
> > -------------------------------
> > JavaMemoryModel mailing list -
> http://www.cs.umd.edu/~pugh/java/memoryModel
>
>
> =====
> Doron Rajwan, mailto:[email protected]
>
> -------------------------------
> JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel
>

-------------------------------
JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel



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