[foreign-memaccess+abi] RFR: 8284300: Explicitly reject layouts that don't have the correct alignment during linking
Jorn Vernee
jvernee at openjdk.org
Tue Sep 20 19:09:02 UTC 2022
On Tue, 20 Sep 2022 17:12:50 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
>> I realized that rejecting layouts that don't have natural alignment also prevents us from supporting packed structs in the future. I tested out the packed struct support and it works on Windows pretty much out of the box. It doesn't work on SysV, some changes to CallArranger are needed. So, there are some options:
>> 1. reject layouts that don't have natural alignment on all platforms (Windows won't be able to use packed structs)
>> 2. reject layouts that don't have natural alignment on platforms besides Windows (yay Windows users)
>> 3. align the status quos: Windows and AArch64 re-compute the alignment. It's not used on Windows, so it can be dropped there. On AArch64 we could "trust" the alignment that is attached to the layout given by the user, same as SysV, but it would fail for packed structs. With the intention of fixing the failure in the future.
>>
>> I'm leaning most towards 1 at the moment, and that's what this patch implements. We can change that approach when we add reliable support for packed structs across platforms.
>
> src/java.base/share/classes/jdk/internal/foreign/abi/SharedUtils.java line 382:
>
>> 380:
>> 381: private static long naturalByteAlignment(MemoryLayout layout) {
>> 382: return alignment(layout, true);
>
> Can you please take a look at that `alignment` routine? I'm not 100% sure it's correct (e.g. for arrays it returns 16 - is that true on all platforms?). Also, note that `AbstractLayout` has an `hasNaturalAlignment` predicate, which seems close to what you need.
Hmm yeah, IIRC the array alignment is only 16 if it is a global variable, so I think we can drop that here in this case. I'll use `hasNaturalAlignment` instead. Good suggestion!
-------------
PR: https://git.openjdk.org/panama-foreign/pull/728
More information about the panama-dev
mailing list