RFR: 8340205: Native linker allows MemoryLayout consisting of only PaddingLayout [v13]

Jorn Vernee jvernee at openjdk.org
Wed Nov 20 19:18:19 UTC 2024


On Mon, 11 Nov 2024 17:28:34 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

> > Maybe we should also check that padding layouts have natural alignment? The alignment of padding layouts can affect the alignment of the enclosing container.
> 
> This makes sense, but I wonder if that would require a change in the javadoc?

Also, we should decide if we want to include this or not. I think this can help prevent silly things like:


MemoryLayout.unionLayout(
    ValueLayout.JAVA_INT,
    MemoryLayout.paddingLayout(8).withByteAlignment(8)):


from being accepted by the check in `checkGroup`.

A single bullet in the criteria for well-formed layouts stating that padding layouts must be naturally aligned seems enough? (And the check in the implementation should be simple as well).

Though, I'm still wondering if we don't want to reject that at the layout API level instead. i.e. have `withByteAlignment` throw an exception for `PaddingLayout`.

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

PR Comment: https://git.openjdk.org/jdk/pull/21041#issuecomment-2489360595


More information about the core-libs-dev mailing list