Swap should be better done native?

Ulf Zibis Ulf.Zibis at gmx.de
Wed Mar 31 16:33:01 PDT 2010


Am 01.04.2010 00:49, schrieb Martin Buchholz:
> Alan, please file a bug and review this change.
>
> Synopsis: Optimize java/nio/Bits.java
> Description:
> Use intrinsified reverseBytes operation; elide no-op constructs
>
>
> So I have a proposed patch:
> http://cr.openjdk.java.net/~martin/webrevs/openjdk7/nioBits.java/
>
> I was surprised that I had written a benchmark for this years ago,
> and also surprised how much faster the swapping got by using
> the intrinsified methods
>
>    

See for example:
class DirectByteBuffer
     ...
     private ByteBuffer putChar(long a, char x) {
         if (unaligned) {
             char y = (x);
             unsafe.putChar(a, (nativeByteOrder ? y : Bits.swap(y)));
         } else {
             Bits.putChar(a, x, bigEndian);
         }
         return this;
     }

1. Is there some reason for char y = (x); ?
I don't understand why first copying to local y.

2.I'm not sure, when unaligned == false would occur.
We should consider, that unsafe.putChar(long, char) would become very 
fast referring latest patch proposals.
Is there any win from Bits.putChar(long, char, boolean) ?

3. This method could return DirectByteBuffer type.

-ulf





More information about the nio-discuss mailing list