[foreign-jextract] Wrong MemoryLayout and VarHandle carrier for integer field

Filip Krakowski krakowski at hhu.de
Thu Aug 27 14:28:11 UTC 2020


Hi,

using just these works fine for me, too. Throwing <infiniband/verbs.h> 
at jextract gives C_BOOL... strange. Could this be related to the clang 
version I use? I am currently at version 10.0.0.

Best regards,
Filip

On 27.08.20 16:10, sundararajan.athijegannathan at oracle.com wrote:
> I tried the following header - just enough to have that struct and 
> dependencies
>
>
> #include <stdint.h>
>
> enum ibv_qp_type {
>         IBV_QPT_RC = 2,
>         IBV_QPT_UC,
>         IBV_QPT_UD,
>         IBV_QPT_RAW_PACKET = 8,
>         IBV_QPT_XRC_SEND = 9,
>         IBV_QPT_XRC_RECV,
>         IBV_QPT_DRIVER = 0xff,
> };
>
> struct ibv_qp_cap {
>         uint32_t                max_send_wr;
>         uint32_t                max_recv_wr;
>         uint32_t                max_send_sge;
>         uint32_t                max_recv_sge;
>         uint32_t                max_inline_data;
> };
>
> struct ibv_qp_init_attr {
>         void                   *qp_context;
>         struct ibv_cq          *send_cq;
>         struct ibv_cq          *recv_cq;
>         struct ibv_srq         *srq;
>         struct ibv_qp_cap       cap;
>         enum ibv_qp_type        qp_type;
>         int                     sq_sig_all;
> };
>
> I don't see C_BOOL for sq_sig_all. Perhaps something more from the 
> context of header is needed (although I wonder what could that be)
>
> Thanks
>
> -Sundar
>
> On 27/08/20 6:31 pm, Filip Krakowski wrote:
>> Hi,
>>
>> this is source file generation. I noticed that the constants class 
>> file is no longer generated (in source mode) and instead several 
>> constants source files are created.
>>
>> Best regards,
>> Filip
>>
>> On 27.08.20 14:54, Maurizio Cimadamore wrote:
>>> Out of curiousity - is this source or classfile generation?
>>>
>>> Maurizio
>>>
>>> On 27/08/2020 12:56, Filip Krakowski wrote:
>>>> Hi,
>>>>
>>>> I already use the latest build (commit 06675b build yesterday 
>>>> 10:28PM - 
>>>> https://coconucos.cs.hhu.de/forschung/jdk/panama-20200826202808-06675b.zip). 
>>>> Other structs containing "int" fields (for example 
>>>> "ibv_device_attr") work well and use "C_INT". I also checked my 
>>>> local header files.
>>>>
>>>> Best regards,
>>>> Filip
>>>>
>>>> On 27.08.20 13:26, sundararajan.athijegannathan at oracle.com wrote:
>>>>> I don't have the complete dependencies on my machine
>>>>>
>>>>> I locally filled the struct definition you gave with appropriate 
>>>>> dependencies (dummy struct, enum declarations) and jextracted it.
>>>>>
>>>>> I see C_INT is being generated as layout for sq_sig_all. I suspect 
>>>>> most likely you're using old panama build. I'd recommend building 
>>>>> latest panama build from repo and trying your header with the same.
>>>>>
>>>>> -Sundar
>>>>>
>>>>> On 27/08/20 4:14 pm, Filip Krakowski wrote:
>>>>>> Hi,
>>>>>>
>>>>>> I would like to report a bug regarding jextract. The header file 
>>>>>> (https://github.com/linux-rdma/rdma-core/blob/master/libibverbs/verbs.h) 
>>>>>> I give to jextract contains the following struct.
>>>>>>
>>>>>>    struct ibv_qp_init_attr {
>>>>>>             void                   *qp_context;
>>>>>>             struct ibv_cq          *send_cq;
>>>>>>             struct ibv_cq          *recv_cq;
>>>>>>             struct ibv_srq         *srq;
>>>>>>             struct ibv_qp_cap       cap;
>>>>>>             enum ibv_qp_type        qp_type;
>>>>>>             int                     sq_sig_all;
>>>>>>    };
>>>>>>
>>>>>>
>>>>>> The Code generated for the "sq_sig_all" field looks like this.
>>>>>>
>>>>>>    private static final MemoryLayout sq_sig_all$LAYOUT_ =C_BOOL;
>>>>>>    private static final VarHandle sq_sig_all$VH_ 
>>>>>> =sq_sig_all$LAYOUT_.varHandle(byte.class);
>>>>>>
>>>>>>    public static int sq_sig_all$get(MemorySegment seg) {
>>>>>>         return (int)verbs_h$constants$3.sq_sig_all$VH().get(seg);
>>>>>>    }
>>>>>>
>>>>>>    public static void 
>>>>>> sq_sig_all$set(jdk.incubator.foreign.MemorySegment seg,int x) {
>>>>>>         verbs_h$constants$3.sq_sig_all$VH().set(seg, x);
>>>>>>    }
>>>>>>
>>>>>> As you can see jextract chooses "C_BOOL" as the MemoryLayout for 
>>>>>> the "sq_sig_all" field and uses "byte" for the VarHandle's 
>>>>>> carrier. In contrast to this, getters and setters work with "int" 
>>>>>> which leads to an Exception during runtime.
>>>>>>
>>>>>>    java.lang.invoke.WrongMethodTypeException: cannot convert
>>>>>>    MethodHandle(VarHandle,MemorySegment,byte)void to
>>>>>>    (VarHandle,MemorySegment,int)void
>>>>>>
>>>>>>
>>>>
>>



More information about the panama-dev mailing list