[concurrency-interest] 8145539: (coll) AbstractMap.keySet and .values should not be volatile

Aleksey Shipilev aleksey.shipilev at oracle.com
Wed Apr 20 09:10:53 EDT 2016

On 04/20/2016 03:01 PM, Volker.Borchert at atis-systems.com wrote:
> I'm just browsing 1.8.0_92 release notes and the following question arose.
> http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/ce72c7641f38 states


> but
>     public NavigableSet<K> navigableKeySet() {
>         KeySet<K> nks = navigableKeySet;
>         return (nks != null) ? nks : (navigableKeySet = new KeySet<>(this));
>     }
> remained unchanged, with navigableKeySet also non-volatile, so I'd think
> the comment above would apply. (Similar for entrySet() and descendingMap().)
> What am I missing?

The block in navigableKeySet() is semantically the same as suggested in
the Javadoc: it reads the non-volatile $navigableKeySet exactly once.
The patch changed keySet() and values() that were doing two racy reads.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: OpenPGP digital signature
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20160420/c0146e39/attachment.bin>

More information about the Concurrency-interest mailing list