jextract: offset not multiple of alignment, causing ExceptionInInitializerError
Sebastian Stenzel
sebastian.stenzel at gmail.com
Thu Jan 14 21:34:27 UTC 2021
Hey,
Today I noticed a strange problem related to the MemoryLayout generated by jextract for the following struct:
```
struct log2phys {
u_int32_t l2p_flags;
off_t l2p_contigbytes;
off_t l2p_devoffset;
};
```
The generated layout looks like this:
```
static final MemoryLayout log2phys$struct$LAYOUT_ = MemoryLayout.ofStruct(
C_INT.withName("l2p_flags"),
C_LONG_LONG.withName("l2p_contigbytes"),
C_LONG_LONG.withName("l2p_devoffset")
).withName("log2phys");
```
During runtime, when the class was loaded and the VarHandle for "l2p_contigbytes" was created, I got the following exception:
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.example.fuse_h$fuse_operations.$LAYOUT(fuse_h.java:14808)
at com.example.fuse_h$fuse_operations.allocate(fuse_h.java:16294)
...
Caused by: java.lang.UnsupportedOperationException: Invalid alignment requirements for layout b64(l2p_contigbytes)[abi/kind=LONG_LONG,layout/name=l2p_contigbytes]
at jdk.incubator.foreign/jdk.internal.foreign.LayoutPath.checkAlignment(LayoutPath.java:273)
at jdk.incubator.foreign/jdk.internal.foreign.LayoutPath.dereferenceHandle(LayoutPath.java:159)
at jdk.incubator.foreign/jdk.incubator.foreign.MemoryLayout.lambda$varHandle$2(MemoryLayout.java:488)
at jdk.incubator.foreign/jdk.incubator.foreign.MemoryLayout.computePathOp(MemoryLayout.java:538)
at jdk.incubator.foreign/jdk.incubator.foreign.MemoryLayout.varHandle(MemoryLayout.java:488)
at com.example.fuse_h_constants_1.<clinit>(fuse_h_constants_1.java:1921)
... 5 more
I set a breakpoint at LayoutPath.checkAlignment and can tell that "l2p_contigbytes" has an offset of 32 bit (sounds reasonable) but an alignment of 64 bit. I have no idea, what all this means, but apparently it is invalid.
I were able to avoid this error in my test project, but I thought I'd better report this in case there is something wrong, as I can see nothing special about aforementioned struct.
Let me know if I can provide any further information!
Sebastian
More information about the panama-dev
mailing list