Varargs bindings do not work in java 19 on the macbook pro M1 MAX

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Mon Oct 24 13:23:44 UTC 2022


Hi Mark,
interesting. On M1 we have currently few issues - see also this:

https://bugs.openjdk.org/browse/JDK-8275584

Stack spilling doesn't always occur correctly, however I note that your 
example should not spill on the stack, so it should be immune.

Is your C code correct? I see you do _two_ va_arg per loop iteration, 
which surely would leave you accessing invalid data. E.g. in this case n 
= 2, so the loop would do two iterations, and va_arg will be called 
_four_ times? Am I missing something?

I'd rewrite it as:

```
     for(int i = 0; i < n; i++) {
         int i = va_arg(ptr, int);
         printf("lala %d", i);
         Sum += i;
     }
```

And test again.

Maurizio

On 24/10/2022 13:40, Mark Hammons wrote:
> Hi all,
>
> I was testing panama on java 19 with my work issued macbook pro, and 
> my varargs method bindings were returning invalid data.
>
> I thought that maybe it was a failure in my own code, but I couldn't 
> work around it so I created a test instance using manually written code:
>
> test("manual varargs") {
> vallinker= Linker.nativeLinker().nn
> valsl= SymbolLookup.loaderLookup().nn
> valmh= linker
> .downcallHandle(
> sl.lookup("add_var").nn.orElseThrow(),
> FunctionDescriptor.of(JAVA_INT, JAVA_INT, JAVA_INT, JAVA_INT)
> )
> .nn;
> valres= MethodHandleFacade.callVariadic(mh, 2, 1, 2).asInstanceOf[Int]
> assertEquals(res, 3)
> }
> #include<stdarg.h>
> #include<stdio.h>
> intadd_var(intn, ...) {
> intSum = 0;
> va_list ptr;
> va_start(ptr, n);
> for(inti = 0; i < n; i++) {
> inti = va_arg(ptr, int);
> printf("lala %d", i);
> Sum += va_arg(ptr, int);
> }
> va_end(ptr);
> returnSum;
> } The output of the test code is consistent with my autogenerated code,
> the Ints are not reaching the add_var function in a proper state, and 
> therefore
> add_var is returning something like 840370212 instead of 3.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/panama-dev/attachments/20221024/d5c658f0/attachment-0001.htm>


More information about the panama-dev mailing list