< prev index next >

test/jdk/java/foreign/TestMemoryAccess.java

Print this page
*** 28,60 ***
   * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false -Xverify:all TestMemoryAccess
   * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true -Xverify:all TestMemoryAccess
   */
  
  import jdk.incubator.foreign.GroupLayout;
! import jdk.incubator.foreign.MemoryLayouts;
  import jdk.incubator.foreign.MemoryLayout;
  import jdk.incubator.foreign.MemoryLayout.PathElement;
  import jdk.incubator.foreign.MemorySegment;
  import jdk.incubator.foreign.ResourceScope;
  import jdk.incubator.foreign.SequenceLayout;
  import jdk.incubator.foreign.ValueLayout;
  
  import java.lang.invoke.VarHandle;
  import java.util.function.Function;
  
  import org.testng.annotations.*;
  import static org.testng.Assert.*;
  
  public class TestMemoryAccess {
  
      @Test(dataProvider = "elements")
!     public void testAccess(Function<MemorySegment, MemorySegment> viewFactory, ValueLayout elemLayout, Class<?> carrier, Checker checker) {
          ValueLayout layout = elemLayout.withName("elem");
!         testAccessInternal(viewFactory, layout, layout.varHandle(carrier), checker);
      }
  
      @Test(dataProvider = "elements")
!     public void testPaddedAccessByName(Function<MemorySegment, MemorySegment> viewFactory, MemoryLayout elemLayout, Class<?> carrier, Checker checker) {
          GroupLayout layout = MemoryLayout.structLayout(MemoryLayout.paddingLayout(elemLayout.bitSize()), elemLayout.withName("elem"));
!         testAccessInternal(viewFactory, layout, layout.varHandle(carrier, PathElement.groupElement("elem")), checker);
      }
  
      @Test(dataProvider = "elements")
!     public void testPaddedAccessByIndexSeq(Function<MemorySegment, MemorySegment> viewFactory, MemoryLayout elemLayout, Class<?> carrier, Checker checker) {
          SequenceLayout layout = MemoryLayout.sequenceLayout(2, elemLayout);
!         testAccessInternal(viewFactory, layout, layout.varHandle(carrier, PathElement.sequenceElement(1)), checker);
      }
  
      @Test(dataProvider = "arrayElements")
!     public void testArrayAccess(Function<MemorySegment, MemorySegment> viewFactory, MemoryLayout elemLayout, Class<?> carrier, ArrayChecker checker) {
          SequenceLayout seq = MemoryLayout.sequenceLayout(10, elemLayout.withName("elem"));
!         testArrayAccessInternal(viewFactory, seq, seq.varHandle(carrier, PathElement.sequenceElement()), checker);
      }
  
      @Test(dataProvider = "arrayElements")
!     public void testPaddedArrayAccessByName(Function<MemorySegment, MemorySegment> viewFactory, MemoryLayout elemLayout, Class<?> carrier, ArrayChecker checker) {
          SequenceLayout seq = MemoryLayout.sequenceLayout(10, MemoryLayout.structLayout(MemoryLayout.paddingLayout(elemLayout.bitSize()), elemLayout.withName("elem")));
!         testArrayAccessInternal(viewFactory, seq, seq.varHandle(carrier, MemoryLayout.PathElement.sequenceElement(), MemoryLayout.PathElement.groupElement("elem")), checker);
      }
  
      @Test(dataProvider = "arrayElements")
!     public void testPaddedArrayAccessByIndexSeq(Function<MemorySegment, MemorySegment> viewFactory, MemoryLayout elemLayout, Class<?> carrier, ArrayChecker checker) {
          SequenceLayout seq = MemoryLayout.sequenceLayout(10, MemoryLayout.sequenceLayout(2, elemLayout));
!         testArrayAccessInternal(viewFactory, seq, seq.varHandle(carrier, PathElement.sequenceElement(), MemoryLayout.PathElement.sequenceElement(1)), checker);
      }
  
      private void testAccessInternal(Function<MemorySegment, MemorySegment> viewFactory, MemoryLayout layout, VarHandle handle, Checker checker) {
          MemorySegment outer_segment;
          try (ResourceScope scope = ResourceScope.newConfinedScope()) {
--- 28,61 ---
   * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=false -Xverify:all TestMemoryAccess
   * @run testng/othervm -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false -Djava.lang.invoke.VarHandle.VAR_HANDLE_IDENTITY_ADAPT=true -Xverify:all TestMemoryAccess
   */
  
  import jdk.incubator.foreign.GroupLayout;
! import jdk.incubator.foreign.MemoryAddress;
  import jdk.incubator.foreign.MemoryLayout;
  import jdk.incubator.foreign.MemoryLayout.PathElement;
  import jdk.incubator.foreign.MemorySegment;
  import jdk.incubator.foreign.ResourceScope;
  import jdk.incubator.foreign.SequenceLayout;
  import jdk.incubator.foreign.ValueLayout;
  
  import java.lang.invoke.VarHandle;
+ import java.nio.ByteOrder;
  import java.util.function.Function;
  
  import org.testng.annotations.*;
  import static org.testng.Assert.*;
  
  public class TestMemoryAccess {
  
      @Test(dataProvider = "elements")
!     public void testAccess(Function<MemorySegment, MemorySegment> viewFactory, ValueLayout elemLayout, Checker checker) {
          ValueLayout layout = elemLayout.withName("elem");
!         testAccessInternal(viewFactory, layout, layout.varHandle(), checker);
      }
  
      @Test(dataProvider = "elements")
!     public void testPaddedAccessByName(Function<MemorySegment, MemorySegment> viewFactory, MemoryLayout elemLayout, Checker checker) {
          GroupLayout layout = MemoryLayout.structLayout(MemoryLayout.paddingLayout(elemLayout.bitSize()), elemLayout.withName("elem"));
!         testAccessInternal(viewFactory, layout, layout.varHandle(PathElement.groupElement("elem")), checker);
      }
  
      @Test(dataProvider = "elements")
!     public void testPaddedAccessByIndexSeq(Function<MemorySegment, MemorySegment> viewFactory, MemoryLayout elemLayout, Checker checker) {
          SequenceLayout layout = MemoryLayout.sequenceLayout(2, elemLayout);
!         testAccessInternal(viewFactory, layout, layout.varHandle(PathElement.sequenceElement(1)), checker);
      }
  
      @Test(dataProvider = "arrayElements")
!     public void testArrayAccess(Function<MemorySegment, MemorySegment> viewFactory, MemoryLayout elemLayout, ArrayChecker checker) {
          SequenceLayout seq = MemoryLayout.sequenceLayout(10, elemLayout.withName("elem"));
!         testArrayAccessInternal(viewFactory, seq, seq.varHandle(PathElement.sequenceElement()), checker);
      }
  
      @Test(dataProvider = "arrayElements")
!     public void testPaddedArrayAccessByName(Function<MemorySegment, MemorySegment> viewFactory, MemoryLayout elemLayout, ArrayChecker checker) {
          SequenceLayout seq = MemoryLayout.sequenceLayout(10, MemoryLayout.structLayout(MemoryLayout.paddingLayout(elemLayout.bitSize()), elemLayout.withName("elem")));
!         testArrayAccessInternal(viewFactory, seq, seq.varHandle(MemoryLayout.PathElement.sequenceElement(), MemoryLayout.PathElement.groupElement("elem")), checker);
      }
  
      @Test(dataProvider = "arrayElements")
!     public void testPaddedArrayAccessByIndexSeq(Function<MemorySegment, MemorySegment> viewFactory, MemoryLayout elemLayout, ArrayChecker checker) {
          SequenceLayout seq = MemoryLayout.sequenceLayout(10, MemoryLayout.sequenceLayout(2, elemLayout));
!         testArrayAccessInternal(viewFactory, seq, seq.varHandle(PathElement.sequenceElement(), MemoryLayout.PathElement.sequenceElement(1)), checker);
      }
  
      private void testAccessInternal(Function<MemorySegment, MemorySegment> viewFactory, MemoryLayout layout, VarHandle handle, Checker checker) {
          MemorySegment outer_segment;
          try (ResourceScope scope = ResourceScope.newConfinedScope()) {

*** 147,44 ***
              //ok, should fail (scope is closed)
          }
      }
  
      @Test(dataProvider = "matrixElements")
!     public void testMatrixAccess(Function<MemorySegment, MemorySegment> viewFactory, MemoryLayout elemLayout, Class<?> carrier, MatrixChecker checker) {
          SequenceLayout seq = MemoryLayout.sequenceLayout(20,
                  MemoryLayout.sequenceLayout(10, elemLayout.withName("elem")));
!         testMatrixAccessInternal(viewFactory, seq, seq.varHandle(carrier,
                  PathElement.sequenceElement(), PathElement.sequenceElement()), checker);
      }
  
      @Test(dataProvider = "matrixElements")
!     public void testPaddedMatrixAccessByName(Function<MemorySegment, MemorySegment> viewFactory, MemoryLayout elemLayout, Class<?> carrier, MatrixChecker checker) {
          SequenceLayout seq = MemoryLayout.sequenceLayout(20,
                  MemoryLayout.sequenceLayout(10, MemoryLayout.structLayout(MemoryLayout.paddingLayout(elemLayout.bitSize()), elemLayout.withName("elem"))));
          testMatrixAccessInternal(viewFactory, seq,
!                 seq.varHandle(carrier,
                          PathElement.sequenceElement(), PathElement.sequenceElement(), PathElement.groupElement("elem")),
                  checker);
      }
  
      @Test(dataProvider = "matrixElements")
!     public void testPaddedMatrixAccessByIndexSeq(Function<MemorySegment, MemorySegment> viewFactory, MemoryLayout elemLayout, Class<?> carrier, MatrixChecker checker) {
          SequenceLayout seq = MemoryLayout.sequenceLayout(20,
                  MemoryLayout.sequenceLayout(10, MemoryLayout.sequenceLayout(2, elemLayout)));
          testMatrixAccessInternal(viewFactory, seq,
!                 seq.varHandle(carrier,
                          PathElement.sequenceElement(), PathElement.sequenceElement(), PathElement.sequenceElement(1)),
                  checker);
      }
  
-     @Test(dataProvider = "badCarriers",
-           expectedExceptions = IllegalArgumentException.class)
-     public void testBadCarriers(Class<?> carrier) {
-         ValueLayout l = MemoryLayouts.BITS_32_LE.withName("elem");
-         l.varHandle(carrier);
-     }
- 
      private void testMatrixAccessInternal(Function<MemorySegment, MemorySegment> viewFactory, SequenceLayout seq, VarHandle handle, MatrixChecker checker) {
          MemorySegment outer_segment;
          try (ResourceScope scope = ResourceScope.newConfinedScope()) {
              MemorySegment segment = viewFactory.apply(MemorySegment.allocateNative(seq, scope));
              boolean isRO = segment.isReadOnly();
--- 148,37 ---
              //ok, should fail (scope is closed)
          }
      }
  
      @Test(dataProvider = "matrixElements")
!     public void testMatrixAccess(Function<MemorySegment, MemorySegment> viewFactory, MemoryLayout elemLayout, MatrixChecker checker) {
          SequenceLayout seq = MemoryLayout.sequenceLayout(20,
                  MemoryLayout.sequenceLayout(10, elemLayout.withName("elem")));
!         testMatrixAccessInternal(viewFactory, seq, seq.varHandle(
                  PathElement.sequenceElement(), PathElement.sequenceElement()), checker);
      }
  
      @Test(dataProvider = "matrixElements")
!     public void testPaddedMatrixAccessByName(Function<MemorySegment, MemorySegment> viewFactory, MemoryLayout elemLayout, MatrixChecker checker) {
          SequenceLayout seq = MemoryLayout.sequenceLayout(20,
                  MemoryLayout.sequenceLayout(10, MemoryLayout.structLayout(MemoryLayout.paddingLayout(elemLayout.bitSize()), elemLayout.withName("elem"))));
          testMatrixAccessInternal(viewFactory, seq,
!                 seq.varHandle(
                          PathElement.sequenceElement(), PathElement.sequenceElement(), PathElement.groupElement("elem")),
                  checker);
      }
  
      @Test(dataProvider = "matrixElements")
!     public void testPaddedMatrixAccessByIndexSeq(Function<MemorySegment, MemorySegment> viewFactory, MemoryLayout elemLayout, MatrixChecker checker) {
          SequenceLayout seq = MemoryLayout.sequenceLayout(20,
                  MemoryLayout.sequenceLayout(10, MemoryLayout.sequenceLayout(2, elemLayout)));
          testMatrixAccessInternal(viewFactory, seq,
!                 seq.varHandle(
                          PathElement.sequenceElement(), PathElement.sequenceElement(), PathElement.sequenceElement(1)),
                  checker);
      }
  
      private void testMatrixAccessInternal(Function<MemorySegment, MemorySegment> viewFactory, SequenceLayout seq, VarHandle handle, MatrixChecker checker) {
          MemorySegment outer_segment;
          try (ResourceScope scope = ResourceScope.newConfinedScope()) {
              MemorySegment segment = viewFactory.apply(MemorySegment.allocateNative(seq, scope));
              boolean isRO = segment.isReadOnly();

*** 225,41 ***
  
      @DataProvider(name = "elements")
      public Object[][] createData() {
          return new Object[][] {
                  //BE, RW
!                 { ID, MemoryLayouts.BITS_8_BE, byte.class, Checker.BYTE },
!                 { ID, MemoryLayouts.BITS_16_BE, short.class, Checker.SHORT },
!                 { ID, MemoryLayouts.BITS_16_BE, char.class, Checker.CHAR },
!                 { ID, MemoryLayouts.BITS_32_BE, int.class, Checker.INT },
!                 { ID, MemoryLayouts.BITS_64_BE, long.class, Checker.LONG },
!                 { ID, MemoryLayouts.BITS_32_BE, float.class, Checker.FLOAT },
!                 { ID, MemoryLayouts.BITS_64_BE, double.class, Checker.DOUBLE },
                  //BE, RO
!                 { IMMUTABLE, MemoryLayouts.BITS_8_BE, byte.class, Checker.BYTE },
!                 { IMMUTABLE, MemoryLayouts.BITS_16_BE, short.class, Checker.SHORT },
!                 { IMMUTABLE, MemoryLayouts.BITS_16_BE, char.class, Checker.CHAR },
!                 { IMMUTABLE, MemoryLayouts.BITS_32_BE, int.class, Checker.INT },
!                 { IMMUTABLE, MemoryLayouts.BITS_64_BE, long.class, Checker.LONG },
!                 { IMMUTABLE, MemoryLayouts.BITS_32_BE, float.class, Checker.FLOAT },
!                 { IMMUTABLE, MemoryLayouts.BITS_64_BE, double.class, Checker.DOUBLE },
                  //LE, RW
!                 { ID, MemoryLayouts.BITS_8_LE, byte.class, Checker.BYTE },
!                 { ID, MemoryLayouts.BITS_16_LE, short.class, Checker.SHORT },
!                 { ID, MemoryLayouts.BITS_16_LE, char.class, Checker.CHAR },
!                 { ID, MemoryLayouts.BITS_32_LE, int.class, Checker.INT },
!                 { ID, MemoryLayouts.BITS_64_LE, long.class, Checker.LONG },
!                 { ID, MemoryLayouts.BITS_32_LE, float.class, Checker.FLOAT },
!                 { ID, MemoryLayouts.BITS_64_LE, double.class, Checker.DOUBLE },
                  //LE, RO
!                 { IMMUTABLE, MemoryLayouts.BITS_8_LE, byte.class, Checker.BYTE },
!                 { IMMUTABLE, MemoryLayouts.BITS_16_LE, short.class, Checker.SHORT },
!                 { IMMUTABLE, MemoryLayouts.BITS_16_LE, char.class, Checker.CHAR },
!                 { IMMUTABLE, MemoryLayouts.BITS_32_LE, int.class, Checker.INT },
!                 { IMMUTABLE, MemoryLayouts.BITS_64_LE, long.class, Checker.LONG },
!                 { IMMUTABLE, MemoryLayouts.BITS_32_LE, float.class, Checker.FLOAT },
!                 { IMMUTABLE, MemoryLayouts.BITS_64_LE, double.class, Checker.DOUBLE },
          };
      }
  
      interface Checker {
          void check(VarHandle handle, MemorySegment segment);
--- 219,41 ---
  
      @DataProvider(name = "elements")
      public Object[][] createData() {
          return new Object[][] {
                  //BE, RW
!                 { ID, ValueLayout.JAVA_BYTE, Checker.BYTE },
!                 { ID, ValueLayout.JAVA_SHORT.withOrder(ByteOrder.BIG_ENDIAN), Checker.SHORT },
!                 { ID, ValueLayout.JAVA_CHAR.withOrder(ByteOrder.BIG_ENDIAN), Checker.CHAR },
!                 { ID, ValueLayout.JAVA_INT.withOrder(ByteOrder.BIG_ENDIAN), Checker.INT },
!                 { ID, ValueLayout.JAVA_LONG.withOrder(ByteOrder.BIG_ENDIAN), Checker.LONG },
!                 { ID, ValueLayout.JAVA_FLOAT.withOrder(ByteOrder.BIG_ENDIAN), Checker.FLOAT },
!                 { ID, ValueLayout.JAVA_DOUBLE.withOrder(ByteOrder.BIG_ENDIAN), Checker.DOUBLE },
                  //BE, RO
!                 { IMMUTABLE, ValueLayout.JAVA_BYTE, Checker.BYTE },
!                 { IMMUTABLE, ValueLayout.JAVA_SHORT.withOrder(ByteOrder.BIG_ENDIAN), Checker.SHORT },
!                 { IMMUTABLE, ValueLayout.JAVA_CHAR.withOrder(ByteOrder.BIG_ENDIAN), Checker.CHAR },
!                 { IMMUTABLE, ValueLayout.JAVA_INT.withOrder(ByteOrder.BIG_ENDIAN), Checker.INT },
!                 { IMMUTABLE, ValueLayout.JAVA_LONG.withOrder(ByteOrder.BIG_ENDIAN), Checker.LONG },
!                 { IMMUTABLE, ValueLayout.JAVA_FLOAT.withOrder(ByteOrder.BIG_ENDIAN), Checker.FLOAT },
!                 { IMMUTABLE, ValueLayout.JAVA_DOUBLE.withOrder(ByteOrder.BIG_ENDIAN), Checker.DOUBLE },
                  //LE, RW
!                 { ID, ValueLayout.JAVA_BYTE, Checker.BYTE },
!                 { ID, ValueLayout.JAVA_SHORT.withOrder(ByteOrder.LITTLE_ENDIAN), Checker.SHORT },
!                 { ID, ValueLayout.JAVA_CHAR.withOrder(ByteOrder.LITTLE_ENDIAN), Checker.CHAR },
!                 { ID, ValueLayout.JAVA_INT.withOrder(ByteOrder.LITTLE_ENDIAN), Checker.INT },
!                 { ID, ValueLayout.JAVA_LONG.withOrder(ByteOrder.LITTLE_ENDIAN), Checker.LONG },
!                 { ID, ValueLayout.JAVA_FLOAT.withOrder(ByteOrder.LITTLE_ENDIAN), Checker.FLOAT },
!                 { ID, ValueLayout.JAVA_DOUBLE.withOrder(ByteOrder.LITTLE_ENDIAN), Checker.DOUBLE },
                  //LE, RO
!                 { IMMUTABLE, ValueLayout.JAVA_BYTE, Checker.BYTE },
!                 { IMMUTABLE, ValueLayout.JAVA_SHORT.withOrder(ByteOrder.LITTLE_ENDIAN), Checker.SHORT },
!                 { IMMUTABLE, ValueLayout.JAVA_CHAR.withOrder(ByteOrder.LITTLE_ENDIAN), Checker.CHAR },
!                 { IMMUTABLE, ValueLayout.JAVA_INT.withOrder(ByteOrder.LITTLE_ENDIAN), Checker.INT },
!                 { IMMUTABLE, ValueLayout.JAVA_LONG.withOrder(ByteOrder.LITTLE_ENDIAN), Checker.LONG },
!                 { IMMUTABLE, ValueLayout.JAVA_FLOAT.withOrder(ByteOrder.LITTLE_ENDIAN), Checker.FLOAT },
!                 { IMMUTABLE, ValueLayout.JAVA_DOUBLE.withOrder(ByteOrder.LITTLE_ENDIAN), Checker.DOUBLE },
          };
      }
  
      interface Checker {
          void check(VarHandle handle, MemorySegment segment);

*** 302,41 ***
  
      @DataProvider(name = "arrayElements")
      public Object[][] createArrayData() {
          return new Object[][] {
                  //BE, RW
!                 { ID, MemoryLayouts.BITS_8_BE, byte.class, ArrayChecker.BYTE },
!                 { ID, MemoryLayouts.BITS_16_BE, short.class, ArrayChecker.SHORT },
!                 { ID, MemoryLayouts.BITS_16_BE, char.class, ArrayChecker.CHAR },
!                 { ID, MemoryLayouts.BITS_32_BE, int.class, ArrayChecker.INT },
!                 { ID, MemoryLayouts.BITS_64_BE, long.class, ArrayChecker.LONG },
!                 { ID, MemoryLayouts.BITS_32_BE, float.class, ArrayChecker.FLOAT },
!                 { ID, MemoryLayouts.BITS_64_BE, double.class, ArrayChecker.DOUBLE },
                  //BE, RO
!                 { IMMUTABLE, MemoryLayouts.BITS_8_BE, byte.class, ArrayChecker.BYTE },
!                 { IMMUTABLE, MemoryLayouts.BITS_16_BE, short.class, ArrayChecker.SHORT },
!                 { IMMUTABLE, MemoryLayouts.BITS_16_BE, char.class, ArrayChecker.CHAR },
!                 { IMMUTABLE, MemoryLayouts.BITS_32_BE, int.class, ArrayChecker.INT },
!                 { IMMUTABLE, MemoryLayouts.BITS_64_BE, long.class, ArrayChecker.LONG },
!                 { IMMUTABLE, MemoryLayouts.BITS_32_BE, float.class, ArrayChecker.FLOAT },
!                 { IMMUTABLE, MemoryLayouts.BITS_64_BE, double.class, ArrayChecker.DOUBLE },
                  //LE, RW
!                 { ID, MemoryLayouts.BITS_8_LE, byte.class, ArrayChecker.BYTE },
!                 { ID, MemoryLayouts.BITS_16_LE, short.class, ArrayChecker.SHORT },
!                 { ID, MemoryLayouts.BITS_16_LE, char.class, ArrayChecker.CHAR },
!                 { ID, MemoryLayouts.BITS_32_LE, int.class, ArrayChecker.INT },
!                 { ID, MemoryLayouts.BITS_64_LE, long.class, ArrayChecker.LONG },
!                 { ID, MemoryLayouts.BITS_32_LE, float.class, ArrayChecker.FLOAT },
!                 { ID, MemoryLayouts.BITS_64_LE, double.class, ArrayChecker.DOUBLE },
                  //LE, RO
!                 { IMMUTABLE, MemoryLayouts.BITS_8_LE, byte.class, ArrayChecker.BYTE },
!                 { IMMUTABLE, MemoryLayouts.BITS_16_LE, short.class, ArrayChecker.SHORT },
!                 { IMMUTABLE, MemoryLayouts.BITS_16_LE, char.class, ArrayChecker.CHAR },
!                 { IMMUTABLE, MemoryLayouts.BITS_32_LE, int.class, ArrayChecker.INT },
!                 { IMMUTABLE, MemoryLayouts.BITS_64_LE, long.class, ArrayChecker.LONG },
!                 { IMMUTABLE, MemoryLayouts.BITS_32_LE, float.class, ArrayChecker.FLOAT },
!                 { IMMUTABLE, MemoryLayouts.BITS_64_LE, double.class, ArrayChecker.DOUBLE },
          };
      }
  
      interface ArrayChecker {
          void check(VarHandle handle, MemorySegment segment, long index);
--- 296,41 ---
  
      @DataProvider(name = "arrayElements")
      public Object[][] createArrayData() {
          return new Object[][] {
                  //BE, RW
!                 { ID, ValueLayout.JAVA_BYTE, ArrayChecker.BYTE },
!                 { ID, ValueLayout.JAVA_SHORT.withOrder(ByteOrder.BIG_ENDIAN), ArrayChecker.SHORT },
!                 { ID, ValueLayout.JAVA_CHAR.withOrder(ByteOrder.BIG_ENDIAN), ArrayChecker.CHAR },
!                 { ID, ValueLayout.JAVA_INT.withOrder(ByteOrder.BIG_ENDIAN), ArrayChecker.INT },
!                 { ID, ValueLayout.JAVA_LONG.withOrder(ByteOrder.BIG_ENDIAN), ArrayChecker.LONG },
!                 { ID, ValueLayout.JAVA_FLOAT.withOrder(ByteOrder.BIG_ENDIAN), ArrayChecker.FLOAT },
!                 { ID, ValueLayout.JAVA_DOUBLE.withOrder(ByteOrder.BIG_ENDIAN), ArrayChecker.DOUBLE },
                  //BE, RO
!                 { IMMUTABLE, ValueLayout.JAVA_BYTE, ArrayChecker.BYTE },
!                 { IMMUTABLE, ValueLayout.JAVA_SHORT.withOrder(ByteOrder.BIG_ENDIAN), ArrayChecker.SHORT },
!                 { IMMUTABLE, ValueLayout.JAVA_CHAR.withOrder(ByteOrder.BIG_ENDIAN), ArrayChecker.CHAR },
!                 { IMMUTABLE, ValueLayout.JAVA_INT.withOrder(ByteOrder.BIG_ENDIAN), ArrayChecker.INT },
!                 { IMMUTABLE, ValueLayout.JAVA_LONG.withOrder(ByteOrder.BIG_ENDIAN), ArrayChecker.LONG },
!                 { IMMUTABLE, ValueLayout.JAVA_FLOAT.withOrder(ByteOrder.BIG_ENDIAN), ArrayChecker.FLOAT },
!                 { IMMUTABLE, ValueLayout.JAVA_DOUBLE.withOrder(ByteOrder.BIG_ENDIAN), ArrayChecker.DOUBLE },
                  //LE, RW
!                 { ID, ValueLayout.JAVA_BYTE, ArrayChecker.BYTE },
!                 { ID, ValueLayout.JAVA_SHORT.withOrder(ByteOrder.LITTLE_ENDIAN), ArrayChecker.SHORT },
!                 { ID, ValueLayout.JAVA_CHAR.withOrder(ByteOrder.LITTLE_ENDIAN), ArrayChecker.CHAR },
!                 { ID, ValueLayout.JAVA_INT.withOrder(ByteOrder.LITTLE_ENDIAN), ArrayChecker.INT },
!                 { ID, ValueLayout.JAVA_LONG.withOrder(ByteOrder.LITTLE_ENDIAN), ArrayChecker.LONG },
!                 { ID, ValueLayout.JAVA_FLOAT.withOrder(ByteOrder.LITTLE_ENDIAN), ArrayChecker.FLOAT },
!                 { ID, ValueLayout.JAVA_DOUBLE.withOrder(ByteOrder.LITTLE_ENDIAN), ArrayChecker.DOUBLE },
                  //LE, RO
!                 { IMMUTABLE, ValueLayout.JAVA_BYTE, ArrayChecker.BYTE },
!                 { IMMUTABLE, ValueLayout.JAVA_SHORT.withOrder(ByteOrder.LITTLE_ENDIAN), ArrayChecker.SHORT },
!                 { IMMUTABLE, ValueLayout.JAVA_CHAR.withOrder(ByteOrder.LITTLE_ENDIAN), ArrayChecker.CHAR },
!                 { IMMUTABLE, ValueLayout.JAVA_INT.withOrder(ByteOrder.LITTLE_ENDIAN), ArrayChecker.INT },
!                 { IMMUTABLE, ValueLayout.JAVA_LONG.withOrder(ByteOrder.LITTLE_ENDIAN), ArrayChecker.LONG },
!                 { IMMUTABLE, ValueLayout.JAVA_FLOAT.withOrder(ByteOrder.LITTLE_ENDIAN), ArrayChecker.FLOAT },
!                 { IMMUTABLE, ValueLayout.JAVA_DOUBLE.withOrder(ByteOrder.LITTLE_ENDIAN), ArrayChecker.DOUBLE },
          };
      }
  
      interface ArrayChecker {
          void check(VarHandle handle, MemorySegment segment, long index);

*** 379,41 ***
  
      @DataProvider(name = "matrixElements")
      public Object[][] createMatrixData() {
          return new Object[][] {
                  //BE, RW
!                 { ID, MemoryLayouts.BITS_8_BE, byte.class, MatrixChecker.BYTE },
!                 { ID, MemoryLayouts.BITS_16_BE, short.class, MatrixChecker.SHORT },
!                 { ID, MemoryLayouts.BITS_16_BE, char.class, MatrixChecker.CHAR },
!                 { ID, MemoryLayouts.BITS_32_BE, int.class, MatrixChecker.INT },
!                 { ID, MemoryLayouts.BITS_64_BE, long.class, MatrixChecker.LONG },
!                 { ID, MemoryLayouts.BITS_32_BE, float.class, MatrixChecker.FLOAT },
!                 { ID, MemoryLayouts.BITS_64_BE, double.class, MatrixChecker.DOUBLE },
                  //BE, RO
!                 { IMMUTABLE, MemoryLayouts.BITS_8_BE, byte.class, MatrixChecker.BYTE },
!                 { IMMUTABLE, MemoryLayouts.BITS_16_BE, short.class, MatrixChecker.SHORT },
!                 { IMMUTABLE, MemoryLayouts.BITS_16_BE, char.class, MatrixChecker.CHAR },
!                 { IMMUTABLE, MemoryLayouts.BITS_32_BE, int.class, MatrixChecker.INT },
!                 { IMMUTABLE, MemoryLayouts.BITS_64_BE, long.class, MatrixChecker.LONG },
!                 { IMMUTABLE, MemoryLayouts.BITS_32_BE, float.class, MatrixChecker.FLOAT },
!                 { IMMUTABLE, MemoryLayouts.BITS_64_BE, double.class, MatrixChecker.DOUBLE },
                  //LE, RW
!                 { ID, MemoryLayouts.BITS_8_LE, byte.class, MatrixChecker.BYTE },
!                 { ID, MemoryLayouts.BITS_16_LE, short.class, MatrixChecker.SHORT },
!                 { ID, MemoryLayouts.BITS_16_LE, char.class, MatrixChecker.CHAR },
!                 { ID, MemoryLayouts.BITS_32_LE, int.class, MatrixChecker.INT },
!                 { ID, MemoryLayouts.BITS_64_LE, long.class, MatrixChecker.LONG },
!                 { ID, MemoryLayouts.BITS_32_LE, float.class, MatrixChecker.FLOAT },
!                 { ID, MemoryLayouts.BITS_64_LE, double.class, MatrixChecker.DOUBLE },
                  //LE, RO
!                 { IMMUTABLE, MemoryLayouts.BITS_8_LE, byte.class, MatrixChecker.BYTE },
!                 { IMMUTABLE, MemoryLayouts.BITS_16_LE, short.class, MatrixChecker.SHORT },
!                 { IMMUTABLE, MemoryLayouts.BITS_16_LE, char.class, MatrixChecker.CHAR },
!                 { IMMUTABLE, MemoryLayouts.BITS_32_LE, int.class, MatrixChecker.INT },
!                 { IMMUTABLE, MemoryLayouts.BITS_64_LE, long.class, MatrixChecker.LONG },
!                 { IMMUTABLE, MemoryLayouts.BITS_32_LE, float.class, MatrixChecker.FLOAT },
!                 { IMMUTABLE, MemoryLayouts.BITS_64_LE, double.class, MatrixChecker.DOUBLE },
          };
      }
  
      interface MatrixChecker {
          void check(VarHandle handle, MemorySegment segment, long row, long col);
--- 373,49 ---
  
      @DataProvider(name = "matrixElements")
      public Object[][] createMatrixData() {
          return new Object[][] {
                  //BE, RW
!                 { ID, ValueLayout.JAVA_BYTE, MatrixChecker.BYTE },
!                 { ID, ValueLayout.JAVA_BOOLEAN, MatrixChecker.BOOLEAN },
!                 { ID, ValueLayout.JAVA_SHORT.withOrder(ByteOrder.BIG_ENDIAN), MatrixChecker.SHORT },
!                 { ID, ValueLayout.JAVA_CHAR.withOrder(ByteOrder.BIG_ENDIAN), MatrixChecker.CHAR },
!                 { ID, ValueLayout.JAVA_INT.withOrder(ByteOrder.BIG_ENDIAN), MatrixChecker.INT },
!                 { ID, ValueLayout.JAVA_LONG.withOrder(ByteOrder.BIG_ENDIAN), MatrixChecker.LONG },
!                 { ID, ValueLayout.ADDRESS.withOrder(ByteOrder.BIG_ENDIAN), MatrixChecker.ADDR },
+                 { ID, ValueLayout.JAVA_FLOAT.withOrder(ByteOrder.BIG_ENDIAN), MatrixChecker.FLOAT },
+                 { ID, ValueLayout.JAVA_DOUBLE.withOrder(ByteOrder.BIG_ENDIAN), MatrixChecker.DOUBLE },
                  //BE, RO
!                 { IMMUTABLE, ValueLayout.JAVA_BYTE, MatrixChecker.BYTE },
!                 { IMMUTABLE, ValueLayout.JAVA_BOOLEAN, MatrixChecker.BOOLEAN },
!                 { IMMUTABLE, ValueLayout.JAVA_SHORT.withOrder(ByteOrder.BIG_ENDIAN), MatrixChecker.SHORT },
!                 { IMMUTABLE, ValueLayout.JAVA_CHAR.withOrder(ByteOrder.BIG_ENDIAN), MatrixChecker.CHAR },
!                 { IMMUTABLE, ValueLayout.JAVA_INT.withOrder(ByteOrder.BIG_ENDIAN), MatrixChecker.INT },
!                 { IMMUTABLE, ValueLayout.JAVA_LONG.withOrder(ByteOrder.BIG_ENDIAN), MatrixChecker.LONG },
!                 { IMMUTABLE, ValueLayout.ADDRESS.withOrder(ByteOrder.BIG_ENDIAN), MatrixChecker.ADDR },
+                 { IMMUTABLE, ValueLayout.JAVA_FLOAT.withOrder(ByteOrder.BIG_ENDIAN), MatrixChecker.FLOAT },
+                 { IMMUTABLE, ValueLayout.JAVA_DOUBLE.withOrder(ByteOrder.BIG_ENDIAN), MatrixChecker.DOUBLE },
                  //LE, RW
!                 { ID, ValueLayout.JAVA_BYTE, MatrixChecker.BYTE },
!                 { ID, ValueLayout.JAVA_BOOLEAN, MatrixChecker.BOOLEAN },
!                 { ID, ValueLayout.JAVA_SHORT.withOrder(ByteOrder.LITTLE_ENDIAN), MatrixChecker.SHORT },
!                 { ID, ValueLayout.JAVA_CHAR.withOrder(ByteOrder.LITTLE_ENDIAN), MatrixChecker.CHAR },
!                 { ID, ValueLayout.JAVA_INT.withOrder(ByteOrder.LITTLE_ENDIAN), MatrixChecker.INT },
!                 { ID, ValueLayout.JAVA_LONG.withOrder(ByteOrder.LITTLE_ENDIAN), MatrixChecker.LONG },
!                 { ID, ValueLayout.ADDRESS.withOrder(ByteOrder.LITTLE_ENDIAN), MatrixChecker.ADDR },
+                 { ID, ValueLayout.JAVA_FLOAT.withOrder(ByteOrder.LITTLE_ENDIAN), MatrixChecker.FLOAT },
+                 { ID, ValueLayout.JAVA_DOUBLE.withOrder(ByteOrder.LITTLE_ENDIAN), MatrixChecker.DOUBLE },
                  //LE, RO
!                 { IMMUTABLE, ValueLayout.JAVA_BYTE, MatrixChecker.BYTE },
!                 { IMMUTABLE, ValueLayout.JAVA_BOOLEAN, MatrixChecker.BOOLEAN },
!                 { IMMUTABLE, ValueLayout.JAVA_SHORT.withOrder(ByteOrder.LITTLE_ENDIAN), MatrixChecker.SHORT },
!                 { IMMUTABLE, ValueLayout.JAVA_CHAR.withOrder(ByteOrder.LITTLE_ENDIAN), MatrixChecker.CHAR },
!                 { IMMUTABLE, ValueLayout.JAVA_INT.withOrder(ByteOrder.LITTLE_ENDIAN), MatrixChecker.INT },
!                 { IMMUTABLE, ValueLayout.JAVA_LONG.withOrder(ByteOrder.LITTLE_ENDIAN), MatrixChecker.LONG },
!                 { IMMUTABLE, ValueLayout.ADDRESS.withOrder(ByteOrder.LITTLE_ENDIAN), MatrixChecker.ADDR },
+                 { IMMUTABLE, ValueLayout.JAVA_FLOAT.withOrder(ByteOrder.LITTLE_ENDIAN), MatrixChecker.FLOAT },
+                 { IMMUTABLE, ValueLayout.JAVA_DOUBLE.withOrder(ByteOrder.LITTLE_ENDIAN), MatrixChecker.DOUBLE },
          };
      }
  
      interface MatrixChecker {
          void check(VarHandle handle, MemorySegment segment, long row, long col);

*** 421,10 ***
--- 423,15 ---
          MatrixChecker BYTE = (handle, segment, r, c) -> {
              handle.set(segment, r, c, (byte)(r + c));
              assertEquals(r + c, (byte)handle.get(segment, r, c));
          };
  
+         MatrixChecker BOOLEAN = (handle, segment, r, c) -> {
+             handle.set(segment, r, c, (r + c) != 0);
+             assertEquals((r + c) != 0, (boolean)handle.get(segment, r, c));
+         };
+ 
          MatrixChecker SHORT = (handle, segment, r, c) -> {
              handle.set(segment, r, c, (short)(r + c));
              assertEquals(r + c, (short)handle.get(segment, r, c));
          };
  

*** 441,26 ***
          MatrixChecker LONG = (handle, segment, r, c) -> {
              handle.set(segment, r, c, r + c);
              assertEquals(r + c, (long)handle.get(segment, r, c));
          };
  
          MatrixChecker FLOAT = (handle, segment, r, c) -> {
              handle.set(segment, r, c, (float)(r + c));
              assertEquals((float)(r + c), (float)handle.get(segment, r, c));
          };
  
          MatrixChecker DOUBLE = (handle, segment, r, c) -> {
              handle.set(segment, r, c, (double)(r + c));
              assertEquals((double)(r + c), (double)handle.get(segment, r, c));
          };
      }
- 
-     @DataProvider(name = "badCarriers")
-     public Object[][] createBadCarriers() {
-         return new Object[][] {
-                 { void.class },
-                 { boolean.class },
-                 { Object.class },
-                 { int[].class }
-         };
-     }
  }
--- 448,21 ---
          MatrixChecker LONG = (handle, segment, r, c) -> {
              handle.set(segment, r, c, r + c);
              assertEquals(r + c, (long)handle.get(segment, r, c));
          };
  
+         MatrixChecker ADDR = (handle, segment, r, c) -> {
+             handle.set(segment, r, c, MemoryAddress.ofLong(r + c));
+             assertEquals(MemoryAddress.ofLong(r + c), (MemoryAddress)handle.get(segment, r, c));
+         };
+ 
          MatrixChecker FLOAT = (handle, segment, r, c) -> {
              handle.set(segment, r, c, (float)(r + c));
              assertEquals((float)(r + c), (float)handle.get(segment, r, c));
          };
  
          MatrixChecker DOUBLE = (handle, segment, r, c) -> {
              handle.set(segment, r, c, (double)(r + c));
              assertEquals((double)(r + c), (double)handle.get(segment, r, c));
          };
      }
  }
< prev index next >