Remove hacks related to the now lifted ByteBuffer/MemorySegment restrictions

This commit is contained in:
Chris Vest 2021-05-11 11:35:38 +02:00
parent 35b1d4a4fe
commit 7b384c3bf2
2 changed files with 6 additions and 36 deletions

View File

@ -1244,23 +1244,7 @@ public final class ByteBufAdaptor extends ByteBuf {
return true;
});
int read;
if (isDirect()) {
// TODO we cannot use off-heap buffers here, until the JDK allows direct byte buffers based on native
// memory segments to be used in IO operations.
ByteBuffer[] copies = new ByteBuffer[components.length];
for (int i = 0; i < copies.length; i++) {
copies[i] = ByteBuffer.allocateDirect(components[i].remaining());
}
read = (int) in.read(copies);
for (int i = 0; i < copies.length; i++) {
ByteBuffer copy = copies[i];
ByteBuffer component = components[i];
component.put(copy.flip()).flip();
}
} else {
read = (int) in.read(components);
}
int read = (int) in.read(components);
if (read > 0) {
writerIndex(read + writerIndex());

View File

@ -237,16 +237,9 @@ class MemSegBuffer extends RcSupport<Buffer, MemSegBuffer> implements Buffer, Re
@Override
public ByteBuffer readableBuffer() {
var buffer = seg.asByteBuffer();
if (buffer.isDirect()) {
// TODO Remove this when the slicing of shared, native segments JDK bug is fixed.
// See https://mail.openjdk.java.net/pipermail/panama-dev/2021-January/011810.html
ByteBuffer tmp = ByteBuffer.allocateDirect(buffer.capacity());
tmp.put(buffer);
buffer = tmp.position(0);
}
buffer = buffer.asReadOnlyBuffer();
// TODO avoid slicing and just set position+limit when JDK bug is fixed.
return buffer.slice(readerOffset(), readableBytes()).order(order);
buffer = buffer.position(readerOffset()).limit(readerOffset() + readableBytes());
return buffer.order(order);
}
@Override
@ -277,24 +270,17 @@ class MemSegBuffer extends RcSupport<Buffer, MemSegBuffer> implements Buffer, Re
@Override
public ByteBuffer writableBuffer() {
var buffer = wseg.asByteBuffer();
if (buffer.isDirect()) {
buffer = buffer.position(writerOffset()).limit(writerOffset() + writableBytes());
} else {
// TODO avoid slicing and just set position when JDK bug is fixed.
buffer = buffer.slice(writerOffset(), writableBytes());
}
buffer = buffer.position(writerOffset()).limit(writerOffset() + writableBytes());
return buffer.order(order);
}
// </editor-fold>
@Override
public long nativeAddress() {
try {
if (seg.isNative()) {
return seg.address().toRawLongValue();
} catch (UnsupportedOperationException e) {
return 0; // This is a heap segment.
}
return 0; // This is a heap segment.
}
@Override