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

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

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 8u66, 9
    • Fix Version/s: 9
    • Component/s: core-libs

      Backports

        Description

        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.


          Attachments

            Issue Links

              Activity

                People

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

                  Dates

                  • Created:
                    Updated:
                    Resolved: