[foreign-jextract] RFR: 8249810: Jextract should generate parameter types with Addressable type

Maurizio Cimadamore mcimadamore at openjdk.java.net
Tue Jul 21 21:40:35 UTC 2020


On Tue, 21 Jul 2020 21:28:28 GMT, Henry Jen <henryjen at openjdk.org> wrote:

>> This patch tweaks jextract so that all foreign functions wrappers use the new Addressable carrier type, as opposed to
>> the more specific MemoryAddress type. This is useful, as now clients can call such functions with either an address or
>> a segment, w/o any need to call `MemorySegment::address`.  The bulk of the changes are in the TypeTranslator visitor,
>> which now has a parameter which says as to whether an addressable should be used. There are also some changes in the
>> HeaderBuilder class, as we now need to call `Addressable::address` on any incoming addressable parameter (since the
>> method handle generated by the linker expects a `MemoryAddress`).
>
> src/jdk.incubator.jextract/share/classes/jdk/incubator/jextract/HeaderBuilder.java line 76:
> 
>> 75:             }
>> 76:             if (sigtype.parameterType(i).equals(Addressable.class)) {
>> 77:                 pExprs.add(pName + ".address()");
> 
> Here we assume the method handle have MemoryAddress type, while this is true in current implementation, it's possible
> that mhtype actually have Addressable if caller chose to do so otherwise.

No, that's not possible. The ABI does not support Addressable as a carrier type for parameter/returns. In other words,
Addressable is a fiction that's only valid in jextract - it is not really taken into account by the guts of the ABI
support.

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

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


More information about the panama-dev mailing list