Vector bulk operations are over-synchronized

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Not an Issue
    • Priority: P4
    • None
    • Affects Version/s: 17, 21, 24
    • Component/s: core-libs

      This shows up in one major codebase that migrated to JDK 17, which still uses Vector, and doing forEach on it. Current implementation of forEach is already synchronized:
      https://github.com/openjdk/jdk/blob/50bed6c67b1edd7736bdf79308d135a4e1047ff0/src/java.base/share/classes/java/util/Vector.java#L1353

      ...but then it calls `elementAt`:
      https://github.com/openjdk/jdk/blob/50bed6c67b1edd7736bdf79308d135a4e1047ff0/src/java.base/share/classes/java/util/Vector.java#L1359C27-L1359C36

      ...which is also synchronized:
      https://github.com/openjdk/jdk/blob/50bed6c67b1edd7736bdf79308d135a4e1047ff0/src/java.base/share/classes/java/util/Vector.java#L464

      Maybe bulk methods should really use `elementData`, not `elementAt`?

            Assignee:
            Xiaolong Peng
            Reporter:
            Aleksey Shipilev
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: