< prev index next >

test/jdk/java/foreign/callarranger/TestSysVCallArranger.java

Print this page
@@ -34,18 +34,20 @@
  
  import jdk.incubator.foreign.FunctionDescriptor;
  import jdk.incubator.foreign.MemoryAddress;
  import jdk.incubator.foreign.MemoryLayout;
  import jdk.incubator.foreign.MemorySegment;
+ import jdk.incubator.foreign.NativeSymbol;
  import jdk.internal.foreign.abi.Binding;
  import jdk.internal.foreign.abi.CallingSequence;
  import jdk.internal.foreign.abi.x64.sysv.CallArranger;
  import org.testng.annotations.DataProvider;
  import org.testng.annotations.Test;
  
  import java.lang.invoke.MethodType;
  
+ import static jdk.incubator.foreign.ValueLayout.ADDRESS;
  import static jdk.internal.foreign.PlatformLayouts.SysV.*;
  import static jdk.internal.foreign.abi.Binding.*;
  import static jdk.internal.foreign.abi.x64.X86_64Architecture.*;
  import static org.testng.Assert.assertEquals;
  import static org.testng.Assert.assertFalse;

@@ -59,14 +61,15 @@
          FunctionDescriptor fd = FunctionDescriptor.ofVoid();
          CallArranger.Bindings bindings = CallArranger.getBindings(mt, fd, false);
  
          assertFalse(bindings.isInMemoryReturn);
          CallingSequence callingSequence = bindings.callingSequence;
-         assertEquals(callingSequence.methodType(), mt.appendParameterTypes(long.class));
-         assertEquals(callingSequence.functionDesc(), fd.appendArgumentLayouts(C_LONG));
+         assertEquals(callingSequence.methodType(), mt.appendParameterTypes(long.class).insertParameterTypes(0, NativeSymbol.class));
+         assertEquals(callingSequence.functionDesc(), fd.appendArgumentLayouts(C_LONG).insertArgumentLayouts(0, ADDRESS));
  
          checkArgumentBindings(callingSequence, new Binding[][]{
+             { unboxAddress(NativeSymbol.class), vmStore(r10, long.class) },
              { vmStore(rax, long.class) }
          });
  
          checkReturnBindings(callingSequence, new Binding[]{});
  

@@ -86,17 +89,18 @@
          FunctionDescriptor fd = FunctionDescriptor.ofVoid(POINT);
          CallArranger.Bindings bindings = CallArranger.getBindings(mt, fd, false);
  
          assertFalse(bindings.isInMemoryReturn);
          CallingSequence callingSequence = bindings.callingSequence;
-         assertEquals(callingSequence.methodType(), mt.appendParameterTypes(long.class));
-         assertEquals(callingSequence.functionDesc(), fd.appendArgumentLayouts(C_LONG));
+         assertEquals(callingSequence.methodType(), mt.appendParameterTypes(long.class).insertParameterTypes(0, NativeSymbol.class));
+         assertEquals(callingSequence.functionDesc(), fd.appendArgumentLayouts(C_LONG).insertArgumentLayouts(0, ADDRESS));
  
          checkArgumentBindings(callingSequence, new Binding[][]{
-                 { dup(), bufferLoad(0, long.class), vmStore(rdi, long.class),
-                   bufferLoad(8, int.class), vmStore(rsi, int.class)},
-                 { vmStore(rax, long.class) },
+             { unboxAddress(NativeSymbol.class), vmStore(r10, long.class) },
+             { dup(), bufferLoad(0, long.class), vmStore(rdi, long.class),
+               bufferLoad(8, int.class), vmStore(rsi, int.class)},
+             { vmStore(rax, long.class) },
          });
  
          checkReturnBindings(callingSequence, new Binding[]{});
  
          assertEquals(bindings.nVectorArgs, 0);

@@ -116,17 +120,18 @@
          FunctionDescriptor fd = FunctionDescriptor.ofVoid(POINT);
          CallArranger.Bindings bindings = CallArranger.getBindings(mt, fd, false);
  
          assertFalse(bindings.isInMemoryReturn);
          CallingSequence callingSequence = bindings.callingSequence;
-         assertEquals(callingSequence.methodType(), mt.appendParameterTypes(long.class));
-         assertEquals(callingSequence.functionDesc(), fd.appendArgumentLayouts(C_LONG));
+         assertEquals(callingSequence.methodType(), mt.appendParameterTypes(long.class).insertParameterTypes(0, NativeSymbol.class));
+         assertEquals(callingSequence.functionDesc(), fd.appendArgumentLayouts(C_LONG).insertArgumentLayouts(0, ADDRESS));
  
          checkArgumentBindings(callingSequence, new Binding[][]{
-                 { dup(), bufferLoad(0, long.class), vmStore(rdi, long.class),
-                         bufferLoad(8, long.class), vmStore(rsi, long.class)},
-                 { vmStore(rax, long.class) },
+             { unboxAddress(NativeSymbol.class), vmStore(r10, long.class) },
+             { dup(), bufferLoad(0, long.class), vmStore(rdi, long.class),
+                     bufferLoad(8, long.class), vmStore(rsi, long.class)},
+             { vmStore(rax, long.class) },
          });
  
          checkReturnBindings(callingSequence, new Binding[]{});
  
          assertEquals(bindings.nVectorArgs, 0);

@@ -145,17 +150,18 @@
          FunctionDescriptor fd = FunctionDescriptor.ofVoid(POINT);
          CallArranger.Bindings bindings = CallArranger.getBindings(mt, fd, false);
  
          assertFalse(bindings.isInMemoryReturn);
          CallingSequence callingSequence = bindings.callingSequence;
-         assertEquals(callingSequence.methodType(), mt.appendParameterTypes(long.class));
-         assertEquals(callingSequence.functionDesc(), fd.appendArgumentLayouts(C_LONG));
+         assertEquals(callingSequence.methodType(), mt.appendParameterTypes(long.class).insertParameterTypes(0, NativeSymbol.class));
+         assertEquals(callingSequence.functionDesc(), fd.appendArgumentLayouts(C_LONG).insertArgumentLayouts(0, ADDRESS));
  
          checkArgumentBindings(callingSequence, new Binding[][]{
-                 { dup(), bufferLoad(0, long.class), vmStore(stackStorage(0), long.class),
-                         bufferLoad(8, long.class), vmStore(stackStorage(1), long.class)},
-                 { vmStore(rax, long.class) },
+             { unboxAddress(NativeSymbol.class), vmStore(r10, long.class) },
+             { dup(), bufferLoad(0, long.class), vmStore(stackStorage(0), long.class),
+                     bufferLoad(8, long.class), vmStore(stackStorage(1), long.class)},
+             { vmStore(rax, long.class) },
          });
  
          checkReturnBindings(callingSequence, new Binding[]{});
  
          assertEquals(bindings.nVectorArgs, 0);

@@ -174,17 +180,18 @@
          FunctionDescriptor fd = FunctionDescriptor.ofVoid(POINT);
          CallArranger.Bindings bindings = CallArranger.getBindings(mt, fd, false);
  
          assertFalse(bindings.isInMemoryReturn);
          CallingSequence callingSequence = bindings.callingSequence;
-         assertEquals(callingSequence.methodType(), mt.appendParameterTypes(long.class));
-         assertEquals(callingSequence.functionDesc(), fd.appendArgumentLayouts(C_LONG));
+         assertEquals(callingSequence.methodType(), mt.appendParameterTypes(long.class).insertParameterTypes(0, NativeSymbol.class));
+         assertEquals(callingSequence.functionDesc(), fd.appendArgumentLayouts(C_LONG).insertArgumentLayouts(0, ADDRESS));
  
          checkArgumentBindings(callingSequence, new Binding[][]{
-                 { dup(), bufferLoad(0, long.class), vmStore(stackStorage(0), long.class),
-                         bufferLoad(8, int.class), vmStore(stackStorage(1), int.class)},
-                 { vmStore(rax, long.class) },
+             { unboxAddress(NativeSymbol.class), vmStore(r10, long.class) },
+             { dup(), bufferLoad(0, long.class), vmStore(stackStorage(0), long.class),
+                     bufferLoad(8, int.class), vmStore(stackStorage(1), int.class)},
+             { vmStore(rax, long.class) },
          });
  
          checkReturnBindings(callingSequence, new Binding[]{});
  
          assertEquals(bindings.nVectorArgs, 0);

@@ -198,14 +205,15 @@
                  C_INT, C_INT, C_INT, C_INT, C_INT, C_INT);
          CallArranger.Bindings bindings = CallArranger.getBindings(mt, fd, false);
  
          assertFalse(bindings.isInMemoryReturn);
          CallingSequence callingSequence = bindings.callingSequence;
-         assertEquals(callingSequence.methodType(), mt.appendParameterTypes(long.class));
-         assertEquals(callingSequence.functionDesc(), fd.appendArgumentLayouts(C_LONG));
+         assertEquals(callingSequence.methodType(), mt.appendParameterTypes(long.class).insertParameterTypes(0, NativeSymbol.class));
+         assertEquals(callingSequence.functionDesc(), fd.appendArgumentLayouts(C_LONG).insertArgumentLayouts(0, ADDRESS));
  
          checkArgumentBindings(callingSequence, new Binding[][]{
+             { unboxAddress(NativeSymbol.class), vmStore(r10, long.class) },
              { vmStore(rdi, int.class) },
              { vmStore(rsi, int.class) },
              { vmStore(rdx, int.class) },
              { vmStore(rcx, int.class) },
              { vmStore(r8, int.class) },

@@ -228,14 +236,15 @@
                  C_DOUBLE, C_DOUBLE, C_DOUBLE, C_DOUBLE);
          CallArranger.Bindings bindings = CallArranger.getBindings(mt, fd, false);
  
          assertFalse(bindings.isInMemoryReturn);
          CallingSequence callingSequence = bindings.callingSequence;
-         assertEquals(callingSequence.methodType(), mt.appendParameterTypes(long.class));
-         assertEquals(callingSequence.functionDesc(), fd.appendArgumentLayouts(C_LONG));
+         assertEquals(callingSequence.methodType(), mt.appendParameterTypes(long.class).insertParameterTypes(0, NativeSymbol.class));
+         assertEquals(callingSequence.functionDesc(), fd.appendArgumentLayouts(C_LONG).insertArgumentLayouts(0, ADDRESS));
  
          checkArgumentBindings(callingSequence, new Binding[][]{
+             { unboxAddress(NativeSymbol.class), vmStore(r10, long.class) },
              { vmStore(xmm0, double.class) },
              { vmStore(xmm1, double.class) },
              { vmStore(xmm2, double.class) },
              { vmStore(xmm3, double.class) },
              { vmStore(xmm4, double.class) },

@@ -262,14 +271,15 @@
                  C_FLOAT, C_FLOAT, C_FLOAT, C_FLOAT, C_FLOAT, C_FLOAT);
          CallArranger.Bindings bindings = CallArranger.getBindings(mt, fd, false);
  
          assertFalse(bindings.isInMemoryReturn);
          CallingSequence callingSequence = bindings.callingSequence;
-         assertEquals(callingSequence.methodType(), mt.appendParameterTypes(long.class));
-         assertEquals(callingSequence.functionDesc(), fd.appendArgumentLayouts(C_LONG));
+         assertEquals(callingSequence.methodType(), mt.appendParameterTypes(long.class).insertParameterTypes(0, NativeSymbol.class));
+         assertEquals(callingSequence.functionDesc(), fd.appendArgumentLayouts(C_LONG).insertArgumentLayouts(0, ADDRESS));
  
          checkArgumentBindings(callingSequence, new Binding[][]{
+             { unboxAddress(NativeSymbol.class), vmStore(r10, long.class) },
              { vmStore(rdi, long.class) },
              { vmStore(rsi, long.class) },
              { vmStore(rdx, long.class) },
              { vmStore(rcx, long.class) },
              { vmStore(r8, long.class) },

@@ -318,14 +328,15 @@
                  C_INT, C_INT, struct, C_INT, C_INT, C_DOUBLE, C_DOUBLE, C_INT, C_INT, C_INT);
          CallArranger.Bindings bindings = CallArranger.getBindings(mt, fd, false);
  
          assertFalse(bindings.isInMemoryReturn);
          CallingSequence callingSequence = bindings.callingSequence;
-         assertEquals(callingSequence.methodType(), mt.appendParameterTypes(long.class));
-         assertEquals(callingSequence.functionDesc(), fd.appendArgumentLayouts(C_LONG));
+         assertEquals(callingSequence.methodType(), mt.appendParameterTypes(long.class).insertParameterTypes(0, NativeSymbol.class));
+         assertEquals(callingSequence.functionDesc(), fd.appendArgumentLayouts(C_LONG).insertArgumentLayouts(0, ADDRESS));
  
          checkArgumentBindings(callingSequence, new Binding[][]{
+             { unboxAddress(NativeSymbol.class), vmStore(r10, long.class) },
              { vmStore(rdi, int.class) },
              { vmStore(rsi, int.class) },
              {
                  dup(),
                  bufferLoad(0, long.class), vmStore(rdx, long.class),

@@ -360,14 +371,15 @@
          FunctionDescriptor fd = FunctionDescriptor.ofVoid( C_POINTER);
          CallArranger.Bindings bindings = CallArranger.getBindings(mt, fd, false);
  
          assertFalse(bindings.isInMemoryReturn);
          CallingSequence callingSequence = bindings.callingSequence;
-         assertEquals(callingSequence.methodType(), mt.appendParameterTypes(long.class));
-         assertEquals(callingSequence.functionDesc(), fd.appendArgumentLayouts(C_LONG));
+         assertEquals(callingSequence.methodType(), mt.appendParameterTypes(long.class).insertParameterTypes(0, NativeSymbol.class));
+         assertEquals(callingSequence.functionDesc(), fd.appendArgumentLayouts(C_LONG).insertArgumentLayouts(0, ADDRESS));
  
          checkArgumentBindings(callingSequence, new Binding[][]{
+             { unboxAddress(NativeSymbol.class), vmStore(r10, long.class) },
              { unboxAddress(), vmStore(rdi, long.class) },
              { vmStore(rax, long.class) },
          });
  
          checkReturnBindings(callingSequence, new Binding[]{});

@@ -381,14 +393,15 @@
          FunctionDescriptor fd = FunctionDescriptor.ofVoid(struct);
          CallArranger.Bindings bindings = CallArranger.getBindings(mt, fd, false);
  
          assertFalse(bindings.isInMemoryReturn);
          CallingSequence callingSequence = bindings.callingSequence;
-         assertEquals(callingSequence.methodType(), mt.appendParameterTypes(long.class));
-         assertEquals(callingSequence.functionDesc(), fd.appendArgumentLayouts(C_LONG));
+         assertEquals(callingSequence.methodType(), mt.appendParameterTypes(long.class).insertParameterTypes(0, NativeSymbol.class));
+         assertEquals(callingSequence.functionDesc(), fd.appendArgumentLayouts(C_LONG).insertArgumentLayouts(0, ADDRESS));
  
          checkArgumentBindings(callingSequence, new Binding[][]{
+             { unboxAddress(NativeSymbol.class), vmStore(r10, long.class) },
              expectedBindings,
              { vmStore(rax, long.class) },
          });
  
          checkReturnBindings(callingSequence, new Binding[]{});

@@ -439,14 +452,16 @@
          FunctionDescriptor fd = FunctionDescriptor.of(struct);
          CallArranger.Bindings bindings = CallArranger.getBindings(mt, fd, false);
  
          assertFalse(bindings.isInMemoryReturn);
          CallingSequence callingSequence = bindings.callingSequence;
-         assertEquals(callingSequence.methodType(), mt.appendParameterTypes(long.class));
-         assertEquals(callingSequence.functionDesc(), fd.appendArgumentLayouts(C_LONG));
+         assertEquals(callingSequence.methodType(), mt.appendParameterTypes(long.class).insertParameterTypes(0, MemorySegment.class, NativeSymbol.class));
+         assertEquals(callingSequence.functionDesc(), fd.appendArgumentLayouts(C_LONG).insertArgumentLayouts(0, ADDRESS, ADDRESS));
  
          checkArgumentBindings(callingSequence, new Binding[][]{
+             { unboxAddress(MemorySegment.class), vmStore(r11, long.class) },
+             { unboxAddress(NativeSymbol.class), vmStore(r10, long.class) },
              { vmStore(rax, long.class) }
          });
  
          checkReturnBindings(callingSequence, new Binding[] {
              allocate(struct),

@@ -469,14 +484,15 @@
          FunctionDescriptor fd = FunctionDescriptor.of(struct);
          CallArranger.Bindings bindings = CallArranger.getBindings(mt, fd, false);
  
          assertTrue(bindings.isInMemoryReturn);
          CallingSequence callingSequence = bindings.callingSequence;
-         assertEquals(callingSequence.methodType(), MethodType.methodType(void.class, MemoryAddress.class, long.class));
-         assertEquals(callingSequence.functionDesc(), FunctionDescriptor.ofVoid(C_POINTER, C_LONG));
+         assertEquals(callingSequence.methodType(), MethodType.methodType(void.class, NativeSymbol.class, MemoryAddress.class, long.class));
+         assertEquals(callingSequence.functionDesc(), FunctionDescriptor.ofVoid(ADDRESS, C_POINTER, C_LONG));
  
          checkArgumentBindings(callingSequence, new Binding[][]{
+             { unboxAddress(NativeSymbol.class), vmStore(r10, long.class) },
              { unboxAddress(), vmStore(rdi, long.class) },
              { vmStore(rax, long.class) }
          });
  
          checkReturnBindings(callingSequence, new Binding[] {});
< prev index next >