Proposal for Direct-X-Buffer change to improve allocation of zero capacity buffers
Rob McKenna
rob.mckenna at oracle.com
Wed Aug 3 13:20:25 UTC 2016
Hi Jon,
I think nio-dev at openjdk.java.net would be a more appropriate venue for this discussion.
-Rob
On 01/08/16 12:24, Jon V. wrote:
> The Direct Buffer does not optimize the allocation of zero capacity
> buffers. I am proposing a simple if( cap != 0 ) condition that will
> bypass most of the setup process.
>
> Here is the current constructor:
>
> Direct$Type$Buffer$RW$(int cap) { // package-private
> #if[rw]
> super(-1, 0, cap, cap);
> boolean pa = VM.isDirectMemoryPageAligned();
> int ps = Bits.pageSize();
> long size = Math.max(1L, (long)cap + (pa ? ps : 0));
> Bits.reserveMemory(size, cap);
>
> long base = 0;
> try {
> base = unsafe.allocateMemory(size);
> } catch (OutOfMemoryError x) {
> Bits.unreserveMemory(size, cap);
> throw x;
> }
> unsafe.setMemory(base, size, (byte) 0);
> if (pa && (base % ps != 0)) {
> // Round up to page boundary
> address = base + ps - (base & (ps - 1));
> } else {
> address = base;
> }
> cleaner = Cleaner.create(this, new Deallocator(base, size, cap));
> att = null;
> #else[rw]
> super(cap);
> #end[rw]
> }
More information about the jdk8u-dev
mailing list