[foreign-memaccess+abi] RFR: 8303017: Passing by-value structs whose size is not power of 2 doesn't work on all platforms [v2]
Maurizio Cimadamore
mcimadamore at openjdk.org
Thu Mar 2 17:47:38 UTC 2023
On Thu, 2 Mar 2023 17:40:18 GMT, Jorn Vernee <jvernee at openjdk.org> wrote:
>> Fix passing of by-value structs whose size is not a power of 2.
>>
>> The issue is that currently we try to do loads using a ValueLayout that is the size of the nearest power of two that can fit the struct (or part of it, if it is passed in multiple registers). For instance, for a struct of size 6, we try to load its value using `ValueLayout.OfLong`, which is size 8, and thus produce an out of bounds error. A similar issue applies to writes.
>>
>> For the solution I've implemented in this patch, I've attached an explicit byte width to BufferLoads/Stores, which indicates the size of the value we want to load/store. The type that is produced by the binding is still the same. For example, loading a struct of size 6 is implemented as an `int` load and a `short` load, which are then combined into a `long`, instead of attempting to do a single `long` load (and failing). This allows us to avoid doing an out of bounds access.
>>
>> I've added a new test that tests a bunch of structs with varying byte sizes being passed in registers and on the stack. Using a nested `char[]` to precisely tweak the byte size of each struct.
>
> Jorn Vernee has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains 12 commits:
>
> - beef up test
> - Merge branch 'foreign-memaccess+abi' into OOB
> - review comments
> - move pickChunkOffset to SharedUtils
> - eyeball BE support
> - forgot bufferStore for AArch64
> - add check + fix aarch64
> - polish
> - polish test
> - chunked in specializer
> - ... and 2 more: https://git.openjdk.org/panama-foreign/compare/a7df48c8...84be4370
Looks good. I agree on validating endianness assumptions.
-------------
Marked as reviewed by mcimadamore (Committer).
PR: https://git.openjdk.org/panama-foreign/pull/806
More information about the panama-dev
mailing list