< prev index next >

test/jdk/java/foreign/callarranger/TestAarch64CallArranger.java

Print this page
@@ -33,18 +33,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.aarch64.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.AArch64.*;
  import static jdk.internal.foreign.abi.Binding.*;
  import static jdk.internal.foreign.abi.aarch64.AArch64Architecture.*;
  import static org.testng.Assert.assertEquals;
  import static org.testng.Assert.assertFalse;

@@ -58,14 +60,16 @@
          FunctionDescriptor fd = FunctionDescriptor.ofVoid();
          CallArranger.Bindings bindings = CallArranger.LINUX.getBindings(mt, fd, false);
  
          assertFalse(bindings.isInMemoryReturn);
          CallingSequence callingSequence = bindings.callingSequence;
-         assertEquals(callingSequence.methodType(), mt);
-         assertEquals(callingSequence.functionDesc(), fd);
+         assertEquals(callingSequence.methodType(), mt.insertParameterTypes(0, NativeSymbol.class));
+         assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS));
  
-         checkArgumentBindings(callingSequence, new Binding[][]{});
+         checkArgumentBindings(callingSequence, new Binding[][]{
+             { unboxAddress(NativeSymbol.class), vmStore(r9, long.class) }
+         });
  
          checkReturnBindings(callingSequence, new Binding[]{});
      }
  
      @Test

@@ -80,14 +84,15 @@
                  C_INT, C_INT);
          CallArranger.Bindings bindings = CallArranger.LINUX.getBindings(mt, fd, false);
  
          assertFalse(bindings.isInMemoryReturn);
          CallingSequence callingSequence = bindings.callingSequence;
-         assertEquals(callingSequence.methodType(), mt);
-         assertEquals(callingSequence.functionDesc(), fd);
+         assertEquals(callingSequence.methodType(), mt.insertParameterTypes(0, NativeSymbol.class));
+         assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS));
  
          checkArgumentBindings(callingSequence, new Binding[][]{
+             { unboxAddress(NativeSymbol.class), vmStore(r9, long.class) },
              { vmStore(r0, int.class) },
              { vmStore(r1, int.class) },
              { vmStore(r2, int.class) },
              { vmStore(r3, int.class) },
              { vmStore(r4, int.class) },

@@ -109,14 +114,15 @@
                  C_INT, C_INT, C_FLOAT, C_FLOAT);
          CallArranger.Bindings bindings = CallArranger.LINUX.getBindings(mt, fd, false);
  
          assertFalse(bindings.isInMemoryReturn);
          CallingSequence callingSequence = bindings.callingSequence;
-         assertEquals(callingSequence.methodType(), mt);
-         assertEquals(callingSequence.functionDesc(), fd);
+         assertEquals(callingSequence.methodType(), mt.insertParameterTypes(0, NativeSymbol.class));
+         assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS));
  
          checkArgumentBindings(callingSequence, new Binding[][]{
+             { unboxAddress(NativeSymbol.class), vmStore(r9, long.class) },
              { vmStore(r0, int.class) },
              { vmStore(r1, int.class) },
              { vmStore(v0, float.class) },
              { vmStore(v1, float.class) },
          });

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

@@ -189,14 +196,15 @@
          FunctionDescriptor fd = FunctionDescriptor.ofVoid(struct1, struct2, C_INT);
          CallArranger.Bindings bindings = CallArranger.LINUX.getBindings(mt, fd, false);
  
          assertFalse(bindings.isInMemoryReturn);
          CallingSequence callingSequence = bindings.callingSequence;
-         assertEquals(callingSequence.methodType(), mt);
-         assertEquals(callingSequence.functionDesc(), fd);
+         assertEquals(callingSequence.methodType(), mt.insertParameterTypes(0, NativeSymbol.class));
+         assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS));
  
          checkArgumentBindings(callingSequence, new Binding[][]{
+             { unboxAddress(NativeSymbol.class), vmStore(r9, long.class) },
              {
                  copy(struct1),
                  unboxAddress(MemorySegment.class),
                  vmStore(r0, long.class)
              },

@@ -219,14 +227,15 @@
          FunctionDescriptor fd = FunctionDescriptor.of(struct);
          CallArranger.Bindings bindings = CallArranger.LINUX.getBindings(mt, fd, false);
  
          assertTrue(bindings.isInMemoryReturn);
          CallingSequence callingSequence = bindings.callingSequence;
-         assertEquals(callingSequence.methodType(), MethodType.methodType(void.class, MemoryAddress.class));
-         assertEquals(callingSequence.functionDesc(), FunctionDescriptor.ofVoid(C_POINTER));
+         assertEquals(callingSequence.methodType(), MethodType.methodType(void.class, NativeSymbol.class, MemoryAddress.class));
+         assertEquals(callingSequence.functionDesc(), FunctionDescriptor.ofVoid(ADDRESS, C_POINTER));
  
          checkArgumentBindings(callingSequence, new Binding[][]{
+             { unboxAddress(NativeSymbol.class), vmStore(r9, long.class) },
              {
                  unboxAddress(),
                  vmStore(r8, long.class)
              }
          });

@@ -242,14 +251,17 @@
          FunctionDescriptor fd = FunctionDescriptor.of(struct);
          CallArranger.Bindings bindings = CallArranger.LINUX.getBindings(mt, fd, false);
  
          assertFalse(bindings.isInMemoryReturn);
          CallingSequence callingSequence = bindings.callingSequence;
-         assertEquals(callingSequence.methodType(), mt);
-         assertEquals(callingSequence.functionDesc(), fd);
+         assertEquals(callingSequence.methodType(), mt.insertParameterTypes(0, MemorySegment.class, NativeSymbol.class));
+         assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS, ADDRESS));
  
-         checkArgumentBindings(callingSequence, new Binding[][]{});
+         checkArgumentBindings(callingSequence, new Binding[][]{
+             { unboxAddress(MemorySegment.class), vmStore(r10, long.class) },
+             { unboxAddress(NativeSymbol.class), vmStore(r9, long.class) }
+         });
  
          checkReturnBindings(callingSequence, new Binding[]{
              allocate(struct),
              dup(),
              vmLoad(r0, long.class),

@@ -268,14 +280,16 @@
          FunctionDescriptor fd = FunctionDescriptor.of(hfa, C_FLOAT, C_INT, hfa);
          CallArranger.Bindings bindings = CallArranger.LINUX.getBindings(mt, fd, false);
  
          assertFalse(bindings.isInMemoryReturn);
          CallingSequence callingSequence = bindings.callingSequence;
-         assertEquals(callingSequence.methodType(), mt);
-         assertEquals(callingSequence.functionDesc(), fd);
+         assertEquals(callingSequence.methodType(), mt.insertParameterTypes(0, MemorySegment.class, NativeSymbol.class));
+         assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS, ADDRESS));
  
          checkArgumentBindings(callingSequence, new Binding[][]{
+             { unboxAddress(MemorySegment.class), vmStore(r10, long.class) },
+             { unboxAddress(NativeSymbol.class), vmStore(r9, long.class) },
              { vmStore(v0, float.class) },
              { vmStore(r0, int.class) },
              {
                  dup(),
                  bufferLoad(0, float.class),

@@ -304,14 +318,15 @@
          FunctionDescriptor fd = FunctionDescriptor.ofVoid(struct, struct, struct);
          CallArranger.Bindings bindings = CallArranger.LINUX.getBindings(mt, fd, false);
  
          assertFalse(bindings.isInMemoryReturn);
          CallingSequence callingSequence = bindings.callingSequence;
-         assertEquals(callingSequence.methodType(), mt);
-         assertEquals(callingSequence.functionDesc(), fd);
+         assertEquals(callingSequence.methodType(), mt.insertParameterTypes(0, NativeSymbol.class));
+         assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS));
  
          checkArgumentBindings(callingSequence, new Binding[][]{
+             { unboxAddress(NativeSymbol.class), vmStore(r9, long.class) },
              {
                  dup(),
                  bufferLoad(0, float.class),
                  vmStore(v0, float.class),
                  dup(),

@@ -357,14 +372,15 @@
              struct, struct, C_INT, C_INT, C_INT, C_INT, C_INT, C_INT, struct, C_INT);
          CallArranger.Bindings bindings = CallArranger.LINUX.getBindings(mt, fd, false);
  
          assertFalse(bindings.isInMemoryReturn);
          CallingSequence callingSequence = bindings.callingSequence;
-         assertEquals(callingSequence.methodType(), mt);
-         assertEquals(callingSequence.functionDesc(), fd);
+         assertEquals(callingSequence.methodType(), mt.insertParameterTypes(0, NativeSymbol.class));
+         assertEquals(callingSequence.functionDesc(), fd.insertArgumentLayouts(0, ADDRESS));
  
          checkArgumentBindings(callingSequence, new Binding[][]{
+             { unboxAddress(NativeSymbol.class), vmStore(r9, long.class) },
              { copy(struct), unboxAddress(MemorySegment.class), vmStore(r0, long.class) },
              { copy(struct), unboxAddress(MemorySegment.class), vmStore(r1, long.class) },
              { vmStore(r2, int.class) },
              { vmStore(r3, int.class) },
              { vmStore(r4, int.class) },

@@ -380,19 +396,21 @@
  
      @Test
      public void testVarArgsInRegs() {
          MethodType mt = MethodType.methodType(void.class, int.class, int.class, float.class);
          FunctionDescriptor fd = FunctionDescriptor.ofVoid(C_INT).asVariadic(C_INT, C_FLOAT);
+         FunctionDescriptor fdExpected = FunctionDescriptor.ofVoid(ADDRESS, C_INT).asVariadic(C_INT, C_FLOAT);
          CallArranger.Bindings bindings = CallArranger.LINUX.getBindings(mt, fd, false);
  
          assertFalse(bindings.isInMemoryReturn);
          CallingSequence callingSequence = bindings.callingSequence;
-         assertEquals(callingSequence.methodType(), mt);
-         assertEquals(callingSequence.functionDesc(), fd);
+         assertEquals(callingSequence.methodType(), mt.insertParameterTypes(0, NativeSymbol.class));
+         assertEquals(callingSequence.functionDesc(), fdExpected);
  
          // This is identical to the non-variadic calling sequence
          checkArgumentBindings(callingSequence, new Binding[][]{
+             { unboxAddress(NativeSymbol.class), vmStore(r9, long.class) },
              { vmStore(r0, int.class) },
              { vmStore(r1, int.class) },
              { vmStore(v0, float.class) },
          });
  

@@ -401,19 +419,21 @@
  
      @Test
      public void testVarArgsOnStack() {
          MethodType mt = MethodType.methodType(void.class, int.class, int.class, float.class);
          FunctionDescriptor fd = FunctionDescriptor.ofVoid(C_INT).asVariadic(C_INT, C_FLOAT);
+         FunctionDescriptor fdExpected = FunctionDescriptor.ofVoid(ADDRESS, C_INT).asVariadic(C_INT, C_FLOAT);
          CallArranger.Bindings bindings = CallArranger.MACOS.getBindings(mt, fd, false);
  
          assertFalse(bindings.isInMemoryReturn);
          CallingSequence callingSequence = bindings.callingSequence;
-         assertEquals(callingSequence.methodType(), mt);
-         assertEquals(callingSequence.functionDesc(), fd);
+         assertEquals(callingSequence.methodType(), mt.insertParameterTypes(0, NativeSymbol.class));
+         assertEquals(callingSequence.functionDesc(), fdExpected);
  
          // The two variadic arguments should be allocated on the stack
          checkArgumentBindings(callingSequence, new Binding[][]{
+             { unboxAddress(NativeSymbol.class), vmStore(r9, long.class) },
              { vmStore(r0, int.class) },
              { vmStore(stackStorage(0), int.class) },
              { vmStore(stackStorage(1), float.class) },
          });
  
< prev index next >