JDK-8026049 : (bf) Intrinsify ByteBuffer.put{Int,Double,Float,...} methods
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 9
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2013-10-08
  • Updated: 2017-08-10
  • Resolved: 2015-03-31
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 9
9 b64Fixed
Related Reports
Blocks :  
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Description
I think the issue can also be solved with VM intrinsics, but it seems simpler to do it with s.m.Unsafe. Current code for non-byte ByteBuffer calls all the way down to Bits, which does:

    static void putIntB(ByteBuffer bb, int bi, int x) {
        bb._put(bi    , int3(x));
        bb._put(bi + 1, int2(x));
        bb._put(bi + 2, int1(x));
        bb._put(bi + 3, int0(x));
    }

The compiler is known to produce distinct writes in these cases. It is beneficial to replace byte-wide stores into the full-width stores. The caveats include: misaligned reads/writes, handling endianness, etc.
Comments
+1 @ Christian Thalinger
14-03-2014

While looking into code generation in Graal I wrote a prototype for these intrinsics (or method replacements). It's possible to do it but only on x86. Instead of doing this in the compiler it would be better to solve this problem on the Java level like java.nio.DirectByteBuffer does by using unsafe loads and stores when the underlying architecture supports it.
14-03-2014

I think this is sound to do in early JDK 9.
08-10-2013