8319820: Use unnamed variables in the FFM implementation

Reviewed-by: mcimadamore
This commit is contained in:
Per Minborg 2023-11-13 10:52:10 +00:00
parent 4d650fe85f
commit b41b00a41c
4 changed files with 25 additions and 34 deletions

View File

@ -558,29 +558,23 @@ public abstract sealed class AbstractMemorySegmentImpl
} else {
bufferScope = MemorySessionImpl.createHeap(bufferRef(bb));
}
long off = bbAddress + ((long)pos << scaleFactor);
long len = (long)size << scaleFactor;
if (base != null) {
return switch (base) {
case byte[] __ ->
new HeapMemorySegmentImpl.OfByte(bbAddress + (pos << scaleFactor), base, size << scaleFactor, readOnly, bufferScope);
case short[] __ ->
new HeapMemorySegmentImpl.OfShort(bbAddress + (pos << scaleFactor), base, size << scaleFactor, readOnly, bufferScope);
case char[] __ ->
new HeapMemorySegmentImpl.OfChar(bbAddress + (pos << scaleFactor), base, size << scaleFactor, readOnly, bufferScope);
case int[] __ ->
new HeapMemorySegmentImpl.OfInt(bbAddress + (pos << scaleFactor), base, size << scaleFactor, readOnly, bufferScope);
case float[] __ ->
new HeapMemorySegmentImpl.OfFloat(bbAddress + (pos << scaleFactor), base, size << scaleFactor, readOnly, bufferScope);
case long[] __ ->
new HeapMemorySegmentImpl.OfLong(bbAddress + (pos << scaleFactor), base, size << scaleFactor, readOnly, bufferScope);
case double[] __ ->
new HeapMemorySegmentImpl.OfDouble(bbAddress + (pos << scaleFactor), base, size << scaleFactor, readOnly, bufferScope);
default -> throw new AssertionError("Cannot get here");
case byte[] _ -> new HeapMemorySegmentImpl.OfByte(off, base, len, readOnly, bufferScope);
case short[] _ -> new HeapMemorySegmentImpl.OfShort(off, base, len, readOnly, bufferScope);
case char[] _ -> new HeapMemorySegmentImpl.OfChar(off, base, len, readOnly, bufferScope);
case int[] _ -> new HeapMemorySegmentImpl.OfInt(off, base, len, readOnly, bufferScope);
case float[] _ -> new HeapMemorySegmentImpl.OfFloat(off, base, len, readOnly, bufferScope);
case long[] _ -> new HeapMemorySegmentImpl.OfLong(off, base, len, readOnly, bufferScope);
case double[] _ -> new HeapMemorySegmentImpl.OfDouble(off, base, len, readOnly, bufferScope);
default -> throw new AssertionError("Cannot get here");
};
} else if (unmapper == null) {
return new NativeMemorySegmentImpl(bbAddress + (pos << scaleFactor), size << scaleFactor, readOnly, bufferScope);
return new NativeMemorySegmentImpl(off, len, readOnly, bufferScope);
} else {
// we can ignore scale factor here, a mapped buffer is always a byte buffer, so scaleFactor == 0.
return new MappedMemorySegmentImpl(bbAddress + pos, unmapper, size, readOnly, bufferScope);
return new MappedMemorySegmentImpl(off, unmapper, len, readOnly, bufferScope);
}
}
@ -721,13 +715,10 @@ public abstract sealed class AbstractMemorySegmentImpl
private static int getScaleFactor(Buffer buffer) {
return switch (buffer) {
case ByteBuffer __ -> 0;
case CharBuffer __ -> 1;
case ShortBuffer __ -> 1;
case IntBuffer __ -> 2;
case FloatBuffer __ -> 2;
case LongBuffer __ -> 3;
case DoubleBuffer __ -> 3;
case ByteBuffer _ -> 0;
case CharBuffer _, ShortBuffer _ -> 1;
case IntBuffer _, FloatBuffer _ -> 2;
case LongBuffer _, DoubleBuffer _ -> 3;
};
}

View File

@ -296,13 +296,13 @@ public final class Utils {
public static BaseAndScale of(Object array) {
return switch (array) {
case byte[] __ -> BaseAndScale.BYTE;
case char[] __ -> BaseAndScale.CHAR;
case short[] __ -> BaseAndScale.SHORT;
case int[] __ -> BaseAndScale.INT;
case float[] __ -> BaseAndScale.FLOAT;
case long[] __ -> BaseAndScale.LONG;
case double[] __ -> BaseAndScale.DOUBLE;
case byte[] _ -> BaseAndScale.BYTE;
case char[] _ -> BaseAndScale.CHAR;
case short[] _ -> BaseAndScale.SHORT;
case int[] _ -> BaseAndScale.INT;
case float[] _ -> BaseAndScale.FLOAT;
case long[] _ -> BaseAndScale.LONG;
case double[] _ -> BaseAndScale.DOUBLE;
default -> throw new IllegalArgumentException("Not a supported array class: " + array.getClass().getSimpleName());
};
}

View File

@ -254,7 +254,7 @@ public final class FallbackLinker extends AbstractLinker {
acquireCallback.accept(addrArg);
argSeg.set(al, 0, addrArg);
}
case GroupLayout __ ->
case GroupLayout _ ->
MemorySegment.copy((MemorySegment) arg, 0, argSeg, 0, argSeg.byteSize()); // by-value struct
case null, default -> {
assert layout == null;

View File

@ -220,7 +220,7 @@ class TypeClass {
}
}
}
case PaddingLayout __ -> {
case PaddingLayout _ -> {
}
case SequenceLayout seq -> {
MemoryLayout elem = seq.elementLayout();