Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8145539

(coll) AbstractMap.keySet and .values should not be volatile

XMLWordPrintable

        A DESCRIPTION OF THE REQUEST :
        AbstractMap has two fields which are declared volatile:

        public abstract class AbstractMap<K,V> implements Map<K,V> {
        .....
            /**
             * Each of these fields are initialized to contain an instance of the
             * appropriate view the first time this view is requested. The views are
             * stateless, so there's no reason to create more than one of each.
             */
            transient volatile Set<K> keySet;
            transient volatile Collection<V> values;
        ....
        }

        This is unnecessary since there is nothing in the API requiring these fields to be volatile.

        JUSTIFICATION :
        Removing volatile will reduce the cost of creating instances extending AbstractMap, as well as invoking e.g. ::values() and ::keySet() on a HashMap. In the application I'm working in hundreds of thousands HashMaps are created each second.


              shade Aleksey Shipilev
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated:
                Resolved: