JDK-8355038 : (bf) ByteBuffer implementations classes do not call specialized putX
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 19,25
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: generic
  • CPU: generic
  • Submitted: 2025-04-17
  • Updated: 2025-04-21
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.
Other
tbdUnresolved
Related Reports
Relates :  
Description
A DESCRIPTION OF THE PROBLEM :
I am working with java.nio.ByteBuffer in performance sensitive code. Upon inspecting the source code for specialized buffers that wrap ByteBuffer (i.e. ByteBufferAsIntBufferB, etc) I have noticed the fact that their putX methods is calling SCOPED_MEMORY_ACCESS.putXUnaligned, whereas my first instinct would be that they should  be calling SCOPED_MEMORY_ACCESS.putX since the position() is always aligned for these buffers.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
This is the template from which the wrapping buffer classes are generated: https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/java/nio/ByteBufferAs-X-Buffer.java.template.

In the template the "put" method always delegates to "SCOPED_MEMORY_ACCESS.put$Memtype$Unaligned"




Comments
Need JMH benchmarks to see if there is an issue.
18-04-2025

The following two lines were added by JDK-8282191: https://github.com/openjdk/jdk/blame/22e8a97a1ce4e1c781fbc6f1e271c477fe95f069/src/java.base/share/classes/java/nio/ByteBufferAs-X-Buffer.java.template#L169 https://github.com/openjdk/jdk/blame/22e8a97a1ce4e1c781fbc6f1e271c477fe95f069/src/java.base/share/classes/java/nio/ByteBufferAs-X-Buffer.java.template#L180
18-04-2025

Impact -> M (Somewhere in-between the extremes) Likelihood -> L (Newly introduced functions) Workaround -> M (Somewhere in-between the extremes) Priority -> P4
18-04-2025