RFR: 8307181: MemoryLayout.structLayout uses undocumented strict alignment constraints

Maurizio Cimadamore mcimadamore at openjdk.org
Wed May 3 14:24:20 UTC 2023


On Wed, 3 May 2023 14:17:02 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

> > Isn't this true also for sequence layouts where, for example, the second element might be misaligned for `sequenceLayout(2, structLayout(JAVA_INT, JAVA_SHORT))`? Or, is this already covered?
> 
> That case already has some javadoc text:
> 
> https://cr.openjdk.org/~pminborg/panama/21/v2/javadoc/api/java.base/java/lang/foreign/MemoryLayout.html#sequenceLayout(long,java.lang.foreign.MemoryLayout)
> 
> (both factories throw if the alignment of the element layout is bigger than its size). It seems like I only forgot to add extra doc for structs.

Actually, now that I look at it, it seems that the exception we raise is not correct. I think we need to throw if the element size is not a multiple of the alignment. That is, the size determines the stride, so that has to be a multiple of the alignment, otherwise it won't work.

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

PR Comment: https://git.openjdk.org/jdk/pull/13770#issuecomment-1533114938


More information about the core-libs-dev mailing list