Re: JavaMemoryModel: Code in the JDK that fails under current memory model

From: Joseph Bowbeer (jozart@csi.com)
Date: Tue Jul 13 1999 - 03:11:47 EDT


1. The implementation of the preferredSize method in Component.java [JDK1.2]
is a good illustration of some of the problematic code in AWT. I believe the
complexity was added both for performance and deadlock avoidance.

    /** java.awt.Component */

    public Dimension preferredSize() {
        /* Avoid grabbing the lock if a reasonable cached size value
         * is available.
         */

        Dimension dim = prefSize;
        if (dim != null && isValid()) {
            return dim;
        }

        synchronized (getTreeLock()) {
            prefSize = (peer != null) ?
                            peer.preferredSize() :
                            getMinimumSize();
            return prefSize;
        }
    }

    /** supporting definitions from java.awt.Component */

    boolean valid = false;

    public boolean isValid() {
        return (peer != null) && valid;
    }

    static final Object LOCK = new AWTTreeLock();
    static class AWTTreeLock {}

    public final Object getTreeLock() {
        return LOCK;
    }

    /** java.awt.Dimension */

    public class Dimension {
        public int width;
        public int height;
    }

2. My other favorite example is the unsynchronized getListenerList method in
javax.swing.event.EventListenerList.

----- Original Message -----
From: Bill Pugh <pugh@cs.umd.edu>
To: <javaMemoryModel@cs.umd.edu>
Sent: Monday, July 12, 1999 11:40 AM
Subject: JavaMemoryModel: Code in the JDK that fails under current memory
model

>
> Has anyone put together a list of places
> in the JDK that assume initialization safety?
>

-------------------------------
This is the JavaMemoryModel mailing list, managed by Majordomo 1.94.4.

To send a message to the list, email JavaMemoryModel@cs.umd.edu
To send a request to the list, email majordomo@cs.umd.edu and put
your request in the body of the message (use the request "help" for help).
For more information, visit http://www.cs.umd.edu/~pugh/java/memoryModel



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