4837564: (bf) Please make DirectByteBuffer performance enhancements
Alan Bateman
Alan.Bateman at oracle.com
Thu Oct 14 05:17:08 PDT 2010
Chris Hegarty wrote:
> Seems fine, some minor comments:
>
> // The "-XX:+PageAlignDirectMemory" option can be used to force
> // *buffer*, allocated by ByteBuffer.allocateDirect, to be page aligned.
>
> typo? buffer -> buffers
Thanks, I'll fix that.
>
>
> Could we cache the value of VM.isDirectMemoryPageAligned() as a
> private static final rather than always invoking
> isDirectMemoryPageAligned from the constructor? Dito for
> Bits.pageSize? Or is it possible for these classes to be loaded before
> these values are initialized?
>
> Also, is there an issue with the publication of pageAlignDirectMemory?
> I can't see that it is every referenced within a sync block or from a
> volatile.
It's probably not worth caching the result of
VM.isDirectMemoryPageAligned as the compiler will inline it. I'm not too
concerned about the initialization because this runs as part of the
initialization of the system classes, run as part of the VM initialiation.
>
> int size = Math.max(1, cap + (pa ? ps : 0));
> Are you concerned with overflow when page alignment is on? I'm just
> trying to understand what this is for, and what will happen if
> <init>(Integer.MAX_VALUE - 1)
Hmm, that's a good point. I don't think this has been noticed before.
With these changes then we'd still have this issue if running with
-XX:+PageAlignDirectMemory. Okay, I'll fix that - thanks for spotting it.
-Alan.
More information about the nio-dev
mailing list