[foreign-memaccess+abi] RFR: 8310362: Improve composability of handle derived from layouts [v2]

Maurizio Cimadamore mcimadamore at openjdk.org
Thu Jun 22 22:50:26 UTC 2023


On Thu, 22 Jun 2023 21:56:36 GMT, Jorn Vernee <jvernee at openjdk.org> wrote:

>> src/java.base/share/classes/java/lang/foreign/MemoryLayout.java line 343:
>> 
>>> 341:      */
>>> 342:     @ForceInline
>>> 343:     default long scale(long offset, long index) {
>> 
>> was thinking... do we want the output of this method to ever be negative? (since it's used as an offset to a segment). Also, should we check for overflows with multiplyExact?
>
> I initially consider negative inputs, I wasn't sure, but thought they might be useful in some cases, so I left them in.
> 
> multiplyExact/addExtact seems like a good idea to use.

If the output of `scale` is always used as an offset parameter in some VH, or memory segment accessor, then I think there's a very strong gravitational pull for making it positive. I can't think of any methods in the MemorySegment API that would be happy with a negative offset, so it seems like a place where bugs might hide, or be reported in unexpected places.

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

PR Review Comment: https://git.openjdk.org/panama-foreign/pull/840#discussion_r1239096181


More information about the panama-dev mailing list