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

Ineffective use of volatile hurts performance of Charset.atBugLevel()

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 10
    • Component/s: core-libs
    • Labels:
      None

      Description

      java.nio.charset.Charset.atBugLevel() uses a volatile variable to cache the value of a system property "sun.nio.cs.bugLevel". The atBugLevel() method is used when a byte array is converted to a string, such as "new String(byteArray, offset, length, charset)".

      This variable need not to be volatile because the system property is a runtime constant and updating the cache variable multiple times produces the same result.

      Reading from a volatile variable in some platforms, such as PPC and ARM, causes extra overhead to synchronize memory accesses with other threads and hurts performance, while there is no overhead in x86 platforms.

      We verified that removing this "volatile" qualifier improved performance by 26% in a POWER8 machine using a micro benchmark that repeatedly creates String object from a byte array.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                clanger Christoph Langer
                Reporter:
                horii Hiroshi Horii
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: