jextract generates downcallHandles where I need upcallStubs
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Mon Dec 28 11:38:31 UTC 2020
On 26/12/2020 09:23, Sebastian Stenzel wrote:
>> On 15. Dec 2020, at 12:31, Maurizio Cimadamore
>> <maurizio.cimadamore at oracle.com
>> <mailto:maurizio.cimadamore at oracle.com>> wrote:
>>
>> Now, it's true that the function pointer type behind "readdir" takes
>> its own function pointer (filler), but that shouldn't be a concern
>> when creating the upcall for (1) - a function pointer is just some
>> MemoryAddress parameter that the upcall receives (and that the
>> runtime of the libfuse library will provide). And, it is true that,
>> in this case jextract will also generate functional interfaces for
>> e.g. the filler upcall, but you don't have to use them in this case
>> (since the filler function pointer will never be generated by you -
>> but by the library) - of course jextract sees a function pointer and
>> generates the corresponding functional interface, it has no way to
>> know which party will allocate the function pointer.
>
> After experimenting with the latest snapshot version of Panama, I was
> now able to implement aforementioned readdir() method. However I still
> don't manage to use the filler function.
>
> jextract will generate a Java method interface from readdir [1] that
> looks like this:
>
> ```
> int readdir(MemoryAddress path, MemoryAddress buf, MemoryAddress
> filler, long offset, MemoryAddress fi)
> ```
>
> Note that the filler is merely a MemoryAddress. From within my Java
> implementation I'd need to call filler, however in order to create a
> downcallHandle from this address, I'd need to know
> the FunctionDescriptor, which is kept package-private within the code
> generated by jextract.
>
> It would be even easier, if there was some way to retrieve a
> MethodHandle from a given MemoryAddress and a known FunctionDescriptor.
>
> Or am I missing something, again?
So, if I understand correctly, what you need here is to pass a function
pointer to the routine that does the "filling" - which is probably a
Java upcall.
Since `fuse_fill_dir_t` is defined as a function type, there should be a
functional interface generated for that parameter (probably called
something like readdir$filler). If you don't see the functional
interface, it is possible you might be missing the fix for:
https://github.com/openjdk/panama-foreign/pull/424
Which, judging from the date in which it has been integrated, it is not
part of the EA.
Are you in a position to do a build of the Panama repo? If so, you could
try if the functional interface is generated in that case.
We plan to spin up another EA as soon as IntelliJ is updated to support
Java 16 in full.
Cheers
Maurizio
>
>
> [1]:
> https://github.com/libfuse/libfuse/blob/fuse_2_9_5/include/fuse.h#L304
> <https://urldefense.com/v3/__https://github.com/libfuse/libfuse/blob/fuse_2_9_5/include/fuse.h*L304__;Iw!!GqivPVa7Brio!KkNaiLpgV2IUiPSEnWuo04SmoGAhT7N5sgbRsGpPJ6OgM7cyleyhPer4wfes780CgDr32fY$>
More information about the panama-dev
mailing list