Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8343188: Investigate ways to simplify MemorySegment::ofBuffer #21764

Closed
wants to merge 13 commits into from
24 changes: 12 additions & 12 deletions src/java.base/share/classes/java/nio/Buffer.java
Original file line number Diff line number Diff line change
@@ -789,11 +789,11 @@ final int checkIndex(int i, int nb) { // package-private
*/
abstract int scaleShifts();

abstract AbstractMemorySegmentImpl arrayBackedSegment(Object base,
long offset,
long length,
boolean readOnly,
MemorySessionImpl bufferScope);
abstract AbstractMemorySegmentImpl heapSegment(Object base,
long offset,
long length,
boolean readOnly,
MemorySessionImpl bufferScope);

final int markValue() { // package-private
return mark;
@@ -931,13 +931,13 @@ public int scaleShifts(Buffer buffer) {

@ForceInline
@Override
public AbstractMemorySegmentImpl arrayBackedSegment(Buffer buffer,
Object base,
long offset,
long length,
boolean readOnly,
MemorySessionImpl bufferScope) {
return buffer.arrayBackedSegment(base, offset, length, readOnly, bufferScope);
public AbstractMemorySegmentImpl heapSegment(Buffer buffer,
Object base,
long offset,
long length,
boolean readOnly,
MemorySessionImpl bufferScope) {
return buffer.heapSegment(base, offset, length, readOnly, bufferScope);
}
});
}
Original file line number Diff line number Diff line change
@@ -258,11 +258,11 @@ class ByteBufferAs$Type$Buffer$RW$$BO$ // package-private

@ForceInline
@Override
AbstractMemorySegmentImpl arrayBackedSegment(Object base,
long offset,
long length,
boolean readOnly,
MemorySessionImpl bufferScope) {
AbstractMemorySegmentImpl heapSegment(Object base,
long offset,
long length,
boolean readOnly,
MemorySessionImpl bufferScope) {
return SegmentFactories.arrayOfByteSegment(base, offset, length, readOnly, bufferScope);
}

Original file line number Diff line number Diff line change
@@ -540,11 +540,11 @@ class Direct$Type$Buffer$RW$$BO$

@ForceInline
@Override
AbstractMemorySegmentImpl arrayBackedSegment(Object base,
long offset,
long length,
boolean readOnly,
MemorySessionImpl bufferScope) {
AbstractMemorySegmentImpl heapSegment(Object base,
long offset,
long length,
boolean readOnly,
MemorySessionImpl bufferScope) {
// Direct buffers are not backed by an array.
throw new UnsupportedOperationException();
}
10 changes: 5 additions & 5 deletions src/java.base/share/classes/java/nio/Heap-X-Buffer.java.template
Original file line number Diff line number Diff line change
@@ -748,11 +748,11 @@ class Heap$Type$Buffer$RW$

@ForceInline
@Override
AbstractMemorySegmentImpl arrayBackedSegment(Object base,
long offset,
long length,
boolean readOnly,
MemorySessionImpl bufferScope) {
AbstractMemorySegmentImpl heapSegment(Object base,
long offset,
long length,
boolean readOnly,
MemorySessionImpl bufferScope) {
return SegmentFactories.arrayOf$Type$Segment(base, offset, length, readOnly, bufferScope);
}
#end[byte]
10 changes: 5 additions & 5 deletions src/java.base/share/classes/java/nio/X-Buffer.java.template
Original file line number Diff line number Diff line change
@@ -2333,11 +2333,11 @@ public abstract sealed class $Type$Buffer

@ForceInline
@Override
AbstractMemorySegmentImpl arrayBackedSegment(Object base,
long offset,
long length,
boolean readOnly,
MemorySessionImpl bufferScope) {
AbstractMemorySegmentImpl heapSegment(Object base,
long offset,
long length,
boolean readOnly,
MemorySessionImpl bufferScope) {
return SegmentFactories.arrayOf$Type$Segment(base, offset, length, readOnly, bufferScope);
}

Original file line number Diff line number Diff line change
@@ -131,11 +131,11 @@ public interface JavaNioAccess {

int scaleShifts(Buffer buffer);

AbstractMemorySegmentImpl arrayBackedSegment(Buffer buffer,
Object base,
long offset,
long length,
boolean readOnly,
MemorySessionImpl bufferScope);
AbstractMemorySegmentImpl heapSegment(Buffer buffer,
Object base,
long offset,
long length,
boolean readOnly,
MemorySessionImpl bufferScope);

}
Original file line number Diff line number Diff line change
@@ -524,7 +524,7 @@ private static AbstractMemorySegmentImpl ofBuffer(Buffer b, long offset, long le
final Object base = NIO_ACCESS.getBufferBase(b);
return (base == null)
? nativeSegment(b, offset, length)
: NIO_ACCESS.arrayBackedSegment(b, base, offset, length, b.isReadOnly(), bufferScope(b));
: NIO_ACCESS.heapSegment(b, base, offset, length, b.isReadOnly(), bufferScope(b));
}

@ForceInline