[foreign-memaccess+abi] RFR: 8303017: Downcall handle IndexOutOfBoundsException on SysV
Jorn Vernee
jvernee at openjdk.org
Mon Feb 27 19:23:47 UTC 2023
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.
-------------
Commit messages:
- move pickChunkOffset to SharedUtils
- eyeball BE support
- forgot bufferStore for AArch64
- add check + fix aarch64
- polish
- polish test
- chunked in specializer
- Chunked load in interpreter
- IOOBE
Changes: https://git.openjdk.org/panama-foreign/pull/806/files
Webrev: https://webrevs.openjdk.org/?repo=panama-foreign&pr=806&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8303017
Stats: 632 lines in 9 files changed: 583 ins; 1 del; 48 mod
Patch: https://git.openjdk.org/panama-foreign/pull/806.diff
Fetch: git fetch https://git.openjdk.org/panama-foreign pull/806/head:pull/806
PR: https://git.openjdk.org/panama-foreign/pull/806
More information about the panama-dev
mailing list