[foreign-jextract] jextract-generated MethodHandle is null

Filip Krakowski krakowski at hhu.de
Fri Sep 18 19:44:34 UTC 2020


Hi,

please ignore the last mail. Just tried looking up the symbol manually 
using LibraryLookup which resulted in an Exception.
For some strange reason the symbol "ibv_post_send" is indeed missing 
within the shared library.

    nm -D libibverbs.so | grep send

    0000000000007f70 T ibv_cmd_post_send
                      U nl_send_auto
                      U nl_send_simple
                      U sendto


Best regards,
Filip

On 18.09.20 21:23, Filip Krakowski wrote:
> Hi,
>
> I had some time to code again and found the following bug in jextract. 
> Since jextract's source mode is not working at the moment 
> (https://bugs.openjdk.java.net/browse/JDK-8252799) I switched to class 
> file mode. The following code (only the important parts) was generated 
> using source mode for better explanation.
>
>    static final FunctionDescriptor ibv_post_send$FUNC_ 
> =FunctionDescriptor.of(C_INT,
>         C_POINTER,
>         C_POINTER,
>         C_POINTER );
>
>    static final MethodHandle ibv_post_send$MH_ 
> =RuntimeHelper.downcallHandle(
>         LIBRARIES,"ibv_post_send",
> "(Ljdk/incubator/foreign/MemoryAddress;Ljdk/incubator/foreign/MemoryAddress;Ljdk/incubator/foreign/MemoryAddress;)I",
>         ibv_post_send$FUNC_,false );
>
>    public static java.lang.invoke.MethodHandle ibv_post_send$MH() 
> {return ibv_post_send$MH_; }
>
>    public static MethodHandle ibv_post_send$MH() {
>         return header_h$constants$0.ibv_post_send$MH();
>    }
>
>    public static @C("int")int ibv_post_send (@C("struct 
> ibv_qp*")Addressable qp, at C("struct ibv_send_wr*")Addressable 
> wr, at C("struct ibv_send_wr**")Addressable bad_wr) {
>         try {
>             return 
> (int)header_h$constants$0.ibv_post_send$MH().invokeExact(qp.address(), 
> wr.address(), bad_wr.address());
>         }catch (Throwable ex) {
>             throw new AssertionError(ex);
>         }
>    }
>
> Calling the generated "ibv_post_send" 
> (https://linux.die.net/man/3/ibv_post_send) method results in a 
> NullPointerException since RuntimeHelper#downcallHandle returns null 
> instead the correct MethodHandle.
>
>    /java.lang.AssertionError: java.lang.NullPointerException: Cannot
>    invoke
> "java.lang.invoke.MethodHandle.invokeExact(jdk.incubator.foreign.MemoryAddress,
>    jdk.incubator.foreign.MemoryAddress,
>    jdk.incubator.foreign.MemoryAddress)" because the return value of
>    "org.linux.rdma.header_h$constants$0.ibv_post_send$MH()" is null/
>
> I also tried creating my own MethodHandle using 
> RuntimeHelper#downcallHandle which also returned null. Interestingly, 
> all previous calls to methods from the same shared library work 
> without problems.
>
> Best regards,
> Filip



More information about the panama-dev mailing list