[foreign-jextract] RFR: 8276136: functional interface extraction broken after API refresh

Maurizio Cimadamore mcimadamore at openjdk.java.net
Thu Oct 28 22:38:49 UTC 2021


This addresses the issue discovered in this thread:

https://mail.openjdk.java.net/pipermail/panama-dev/2021-September/015144.html

The issue is causes by the fact that the new linker changes introduce an asymmetry between the method type of the downcall and that of an upcall. Downcall have `Addressable` for parameters passed by-reference, and `MemoryAddress` for by-reference returns. Upcalls adopt the dual scheme (`MemoryAddress` for parameters, `Addressable` for return values).

This patch bridges the two schemes by inserting the required casts which keep `invokeExact` happy in the case where we generate a functional interface implementation which calls the upcall stub address.

To do that I had to dig a bit in `TypeTranslator` to make the type translation context-dependent. I also had to enhance `FunctionInfo` so that it could carry the "reverse" method type in the upcall case.

I've added a test which checks a function pointer which takes an address and returns another address - which stresses both argument and return mismatch.

-------------

Commit messages:
 - Tweak generation of functional interface to reflect linker changes

Changes: https://git.openjdk.java.net/panama-foreign/pull/605/files
 Webrev: https://webrevs.openjdk.java.net/?repo=panama-foreign&pr=605&range=00
  Issue: https://bugs.openjdk.java.net/browse/JDK-8276136
  Stats: 91 lines in 9 files changed: 27 ins; 24 del; 40 mod
  Patch: https://git.openjdk.java.net/panama-foreign/pull/605.diff
  Fetch: git fetch https://git.openjdk.java.net/panama-foreign pull/605/head:pull/605

PR: https://git.openjdk.java.net/panama-foreign/pull/605


More information about the panama-dev mailing list