Swap should be better done native?
Martin Buchholz
martinrb at google.com
Wed Mar 31 17:19:43 PDT 2010
On Wed, Mar 31, 2010 at 16:33, Ulf Zibis <Ulf.Zibis at gmx.de> wrote:
> 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.
Because it's machine-generated from the strange
Direct-X-Buffer-bin.java.template
> 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.
Why wouldn't it already be very fast?
Martin
More information about the nio-discuss
mailing list