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

(coll) modCount should not be volatile

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 7
    • 7
    • core-libs
    • b25
    • generic
    • generic
    • Not verified

      Collections use a modCount field to track changes to data structures,
      so they can throw ConcurrentModificationException if another thread
      unexpectedly modifies the collection (rather than corrupting the data
      and carrying on).

      Some collections mark modCount as volatile; some do not.
      Since the modCount mechanism comes with no guarantees, and users of
      single-threaded collections do not expect to pay the (high) price
      of a volatile write on every modification operation, the volatile
      modifier should be removed.

      Here are the uses of volatile to be removed:

      ./java/util/HashMap.java:177: transient volatile int modCount;
      ./java/util/IdentityHashMap.java:176: private transient volatile int modCount;
      ./java/util/WeakHashMap.java:185: volatile int modCount;

            martin Martin Buchholz
            martin Martin Buchholz
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: