Skip to content

Commit

Permalink
8319820: Use unnamed variables in the FFM implementation
Browse files Browse the repository at this point in the history
Reviewed-by: mcimadamore
  • Loading branch information
minborg authored and pull[bot] committed Jan 31, 2024
1 parent dabc525 commit 8257233
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -558,29 +558,23 @@ public static AbstractMemorySegmentImpl ofBuffer(Buffer bb) {
} 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);
}
}

Expand Down Expand Up @@ -721,13 +715,10 @@ public static long mismatch(MemorySegment srcSegment, long srcFromOffset, long s

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;
};
}

Expand Down
14 changes: 7 additions & 7 deletions src/java.base/share/classes/jdk/internal/foreign/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -296,13 +296,13 @@ public record BaseAndScale(int base, long scale) {

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());
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ private static void writeValue(Object arg, MemoryLayout layout, MemorySegment ar
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ private static void groupByEightBytes(MemoryLayout layout,
}
}
}
case PaddingLayout __ -> {
case PaddingLayout _ -> {
}
case SequenceLayout seq -> {
MemoryLayout elem = seq.elementLayout();
Expand Down

0 comments on commit 8257233

Please sign in to comment.