JDK-8157296 : Remove fork to xxcodeArrayLoop() and xxcodeBufferLoop() in sun.nio.cs coders
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.nio.charsets
  • Affected Version: 9
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • OS: generic
  • CPU: generic
  • Submitted: 2016-05-18
  • Updated: 2025-01-29
  • Resolved: 2025-01-29
Related Reports
Blocks :  
Description
A DESCRIPTION OF THE REQUEST :
Use same code on heap buffers and direct buffers.

JUSTIFICATION :
Since access to heap buffers and direct buffers is now optimized via Unsafe [1], there is no more need to separately optimize the code.
[1] https://bugs.openjdk.java.net/browse/JDK-8149469

ACTUAL -
        protected CoderResult decodeLoop(ByteBuffer src,
                                         CharBuffer dst)
        {
            if (src.hasArray() && dst.hasArray())
                return decodeArrayLoop(src, dst);
            else
                return decodeBufferLoop(src, dst);
        }



Comments
Given [~martin]'s comments and that Charsets are basically frozen, closing this as Won't Fix.
29-01-2025

The performance issue could be solved by bug JDK-6509032. See also: https://bugs.openjdk.org/browse/JDK-8158695?focusedCommentId=14161141&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-14161141
10-03-2023

I would not do this. Charset implementations are performance critical. It's true that there's a huge amount of errorprone code duplication in the parallel decodeArrayLoop and decodeBufferLoop methods, but that price has been paid and there's no ongoing maintenance cost, since nobody is introducing new Charsets. Anyone who takes this on should do lots of microbenchmarking with various JITs including C1.
06-03-2023