[foreign-abi] On invokers

Nick Gasson nick.gasson at arm.com
Fri Oct 25 07:11:47 UTC 2019


Hi Jorn,

Thanks for the feedback.

> 
> I think your first solution is causing some undefined behaviour; The
> argument buffer allocates number-of-stack-storages * STACK_SLOT_SIZE
> bytes for stack arguments (See the constructor of ProgrammableInvoker).
> So if you try to pass an argument that is bigger than STACK_SLOT_SIZE
> with a single binding it's going to read/write out of bounds of the
> allocated space. I think the fact that it worked in some cases is
> coincidental.
> 
> Your current solution looks good to me (cutting up the struct in to
> STACK_SLOT_SIZEd pieces and generating a binding for each). Your idea of
> doing a bulk copy is interesting as well, but I'd like to keep breaking
> up the arguments into chunks, since this seems easier to intrinsify
> based on the current JIT code for doing runtime calls.
> 

OK, I see that now. I think in the upcall case it worked because the 
stack memory comes from

    MemoryAddressImpl.ofNative((long) 
VH_LONG.get(buffer.offset(layout.stack_args)));

And that MemorySegment covers all the memory. I've changed it do the 
stack-slot-at-a-time copy in both directions. Updated webrev here:

http://cr.openjdk.java.net/~ngasson/panama/new-invoker/webrev.02/

After I did that I ran into a small bug in the pointer function in 
ProgrammableUpcallHandler: it needs to offset by the the stack slot 
index multiplied by the type size, like ProgrammableInvoker does (fixed 
in the above patch).

Thanks,
Nick


More information about the panama-dev mailing list