Commit Graph

8 Commits

Author SHA1 Message Date
Chris Vest
6d4ad29149 Implement Composite buffers
Motivation:
Composite buffers make it possible to combine the data from multiple buffers and present them as one, without copying the contents. Each access primitive has slightly higher overhead, though, so it is encouraged to make measurements before decided whether to compose or copy.

Modification:
A CompositeBuf implementation has been added, along with a Buf#compose factory method.
The composite buffer behaves exactly the same as non-composed buffers.
2020-11-17 15:26:57 +01:00
Chris Vest
94e3a00fd4 Update with support for shared segments
Motivation:
 We wish to make as little use of Unsafe as possible, yet have a flexible buffer API.
 With the proposed support for shared segments, we're able to clean up our buffer API and simplify the implementation.

Modification:
 With shared segments, we are able to implement TransferSend using supported APIs.
 This allows us to remove RendezvousSend, and also our hacks in Statics.
 TransferSend now works by first creating a shared segment and using that for the handover.
 On the receiving end, if the segment was originally thread-confined, it will once again become
 confined, but this time to the receiver thread.
 Shared segments are just passed directly to their new owners.
 Pooled allocators always create shared memory segments for their buffers, so they can be
 shared easily via the pool.

Result:
 We now have buffer ownership transfer with nice, convenient, APIs, and we have buffer pooling,
 all using supported APIs.
2020-11-17 15:26:57 +01:00
Chris Vest
f6e5d26ce8 Fix compilation and all checkstyle complaints 2020-11-17 15:26:57 +01:00
Chris Vest
09f9b5a158 Flesh out the Buf interface and simplify the generics
The `Buf` type no longer needs any other qualifying type annotations to specify.
It is itself a non-parameterised type now, which makes it a lot simpler for people to use.
It's wealth of accessor methods have also been expanded, and tests have been added.
There is, however, still a fair number of methods to add before it resembles a `ByteBuf` replacement.
2020-11-17 15:26:57 +01:00
Chris Vest
7ab05dae7a Make Rc an interface
This is necessary in preparation for making BBuf an interface.
2020-11-17 15:26:57 +01:00
Chris Vest
b5abfdd1f8 Address PR comments
Motivation:
 Clean up code to fix PR comments.

Modification:
 Rename a method and add javadocs.

Result:
 Code is cleaner and mode documented.
2020-11-17 15:26:57 +01:00
Chris Vest
8b0ea44f02 Add support for closing BBuf/MemorySegment via Cleaner
Motivation:
 Keeping track of refcounts is hard for client code.
 It is much easier to rely on the GC for cleanup.
Modification:
 Add a new pool, native allocator implementation, that uses the Cleaner API to prevent leaks.
 Native memory accounting, which is not built into the JDK for MemorySegments, has also been added to the allocators so the Cleaner based implementation can be tested.
Result:
 We have a leak resistant allocator for BBuf.
2020-11-17 15:26:57 +01:00
Chris Vest
57af0f0e26 First spike prototype of a ByteBuf implementation based on MemorySegment
Motivation:
Future versions of Java will introduce a new API for working with off-heap and on-heap memory alike.
This API _could_ potentially relieve us of many of our use cases for Unsafe.
We wish to explore how suitable these APIs are for this task.

Modification:
Add an entirely separate version of the Netty ByteBuf API, implemented in terms of MemorySegment.
No existing code is changed at this time.
The current prototype is only to prove the concept, and does not aim to be a full replacement.

Result:
We are able to build a fairly nice API, but with caveats.
Restrictions in the current (JDK 16 EA) MemorySegment API, around how ownership is transferred between threads, means we are currently still relying on Unsafe.
While our use of Unsafe could be reduced, it can not be eliminated in our ByteBuf API, because we are relying on it to work around the current ownership restrictions.
I believe it is _possible_ to create a safe ownership transfer API at the JDK level, so hopefully this restriction can be lifted in the future.
2020-11-17 15:26:57 +01:00