[foreign-memaccess] RFR: 8248487: Add static helpers to access segments (continued) - benchmark fix

Jorn Vernee jvernee at openjdk.java.net
Fri Jul 3 18:36:28 UTC 2020


On Fri, 3 Jul 2020 18:22:43 GMT, Jorn Vernee <jvernee at openjdk.org> wrote:

>> This patch fixes the benchmarks that were referring to the previous accessor names.
>> 
>> It also addresses a performance loophole with long multiplication being used even when index fits in an int.
>
> src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/MemoryAccess.java line 2046:
> 
>> 2045:         }
>> 2046:     }
>> 2047: }
> 
> This looks potentially problematic. `index * size` can overflow when casting to int, when it would not have overflown
> if the operands were `long`. For small segments we do something similar, but it's less of a problem there since we know
> the segment size fits in an int, so if there's overflow the access would have been out of bounds any ways. I think here
> you will have to pass in the `segment()` from the accessed address, and then use the isSmall() predicate as the
> criteria for doing the cast or not.

Maybe MemoryAddressProxy::multiplyOffsets can be used?

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

PR: https://git.openjdk.java.net/panama-foreign/pull/233


More information about the panama-dev mailing list