[foreign] RFR: 8223808: initial port for AArch64

Nick Gasson nick.gasson at arm.com
Tue May 21 07:29:18 UTC 2019


Hi Maurizio

On 20/05/2019 19:04, Maurizio Cimadamore wrote:
>
> I guess that means that, e.g. if your native function takes nothing and
> returns a big struct, we will need to make a long array that is big
> enough to contain all register values (which are unused in this case)
> and fill it with SKIP steps, just in order to use the last step?

Yes, that's exactly what happens. So the shuffle recipe looks like:

  ShuffleRecipe: {
    Operations: {
  [STOP, STOP, STOP, SKIP, SKIP, SKIP, SKIP, SKIP, SKIP, SKIP, SKIP, PULL, STOP, STOP, STOP, STOP, STOP, PULL, STOP, STOP]  }
  }

It works but it feels quite hacky.

>
> I think that could work - but at the same time, patch (2) seem more or
> less in the spirit of what was done with X87 registers (which are only
> supported on Intel platforms), so I can also live with that one, which
> has the advantage of being cleaner.

OK, I think patch [2] is neater as well. I'll squash that onto the main
patch.

>
> I wouldn't bother with DirectInvoker for now; you can enable it in a
> follow up patch if you find out what the issue is, and want to fix it -
> but as you say, it's probably better to focus on linkToNative which is
> gonna be the future here.
>

So the error I get is:

java.lang.IllegalArgumentException: Invalid size: 36
	at java.base/jdk.internal.foreign.memory.BoundedPointer.unsafeGetBits(BoundedPointer.java:331)
	at java.base/jdk.internal.foreign.memory.BoundedPointer.getBits(BoundedPointer.java:160)
	at java.base/jdk.internal.foreign.abi.DirectSignatureShuffler.structToLong(DirectSignatureShuffler.java:343)

This happens because for >16 byte structs we now have an integer
argument register that holds a pointer to the struct rather than the
struct's data packed into that register. I can fix it with the simple
change below, if that's acceptable?

@@ -410,12 +410,17 @@ public class DirectSignatureShuffler {
         switch (binding.storage().getStorageClass()) {
             case X87_RETURN_REGISTER:
             case STACK_ARGUMENT_SLOT:
+            case INDIRECT_RESULT_REGISTER:
                 //arguments passed in memory not supported
                 return false;
             case VECTOR_ARGUMENT_REGISTER:
             case VECTOR_RETURN_REGISTER:
                 //avoid passing around floats as doubles as that leads to trouble
                 return (binding.argument().layout().bitsSize() / 8) == binding.storage().getSize();
+            case INTEGER_ARGUMENT_REGISTER:
+                // On some platforms large by-value structures are passed by
+                // pointer in integer argument registers
+                return (binding.argument().layout().bitsSize() / 8) <= binding.storage().getSize();
             default:
                 return true;
         }


Thanks,
Nick


More information about the panama-dev mailing list