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

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

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 10
    • None
    • core-libs
    • None

      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.

            clanger Christoph Langer
            horii Hiroshi Horii (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: