Cliff Click wrote:
> If I see a dead volatile load I can remove the actual load, but
> a volatile ref includes a 'MemBarAcquire' (in HotSpot parlance)
> to help prevent various compiler & hardware reorderings.  Can I
> remove the MemBarAcquire as well?
If I understand you right - NO!  :) The use of a 'dummy' access to a
volatile is often used purely for the memory affects. I have a
hashtable-like data structure that allows concurrent read access without
locks. A 'dead' read of a volatile is used to ensure fresh loads of the data
variables.
        int get(int key, byte[] t_bc, int t_off, int t_len) {
            int hash = syncFlag;   // volatile read to ensure visibility
            hash = mask_ & key; // map the hash key to a bin
            int offset = values_[hash];
            // If we see a value for values_[hash] then we know that the
            // corresponding data has been written to the byte array.
            // Otherwise this key is not present.
            if (offset == 0) return -1; // not present
            // see if it matches
            if (key == keys_[hash] &&
                compareBytes(offset, t_bc, t_off, t_len)) {
                return offset; // found it
            }
            else if (key == 0 && offset == 0) { // odd case when hash==0
                return -1; // not present
            }
            else {
                // this key is not in the primary table, so search
                // the collision tables
                return getCollision(key, t_bc, t_off, t_len);
            }
        }
I'm pretty sure Doug Lea uses (or will use in a JMM compliant VM) the same
sort of approach in his ConcurrentReadersHashMap etc.
David Holmes
-------------------------------
JavaMemoryModel mailing list - http://www.cs.umd.edu/~pugh/java/memoryModel
This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:00:40 EDT