JDK-8182743 : Ineffective use of volatile hurts performance of Charset.atBugLevel()
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.nio.charsets
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • CPU: arm,ppc
  • Submitted: 2017-06-23
  • Updated: 2019-02-15
  • Resolved: 2017-07-02
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 10
10 b14Fixed
Related Reports
CSR :  
Relates :  
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.
Comments
Proposed to solve this by completely removing method atBugLevel(). Awaiting CSR approval.
28-06-2017

Likely resolved in 9 already by virtue of JDK-8174831.
23-06-2017