RFR (XS) 8145539: (coll) AbstractMap.keySet and .values should not be volatile

Doug Lea dl at cs.oswego.edu
Thu Dec 17 15:07:53 UTC 2015


On 12/16/2015 05:53 PM, Aleksey Shipilev wrote:
> Hi,
>
> Since the dawn of OpenJDK, AbstractMap.keySet and .value were defined as
> package-private volatile fields. Their only use is to cache keySet and
> valueSet implementations from java.util collections.

I think these were declared volatile to be more clearly JMM compliant.
They are definitely OK without it, but you should probably add some
rationale in documentation, mentioning that all java.util.Map view class
implementations using these fields have no non-final fields (or any
fields at all except for outer-this).

-Doug




More information about the core-libs-dev mailing list