RFR: 8287244: Add bound check in indexed memory access var handle [v2]

Paul Sandoz psandoz at openjdk.java.net
Tue May 24 16:26:27 UTC 2022


On Tue, 24 May 2022 15:28:27 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> Constructing indexed var handles using the `MemoryLayout` API produces `VarHandle` which do not check the input indices for out-of-bounds conditions.
>> While this can never result in a VM crash (after all the memory segment will protect against "true" OOB access), it is still possible for an access expression to refer to parts of a segment that are logically unrelated.
>> 
>> This patch adds a "logical" bound check to all indexed var handles generated using the layout API.
>> Benchmarks are not affected by the check. Users are still able to create custom "unchecked" var handles, using the combinator API in `MethodHandles`.
>
> Maurizio Cimadamore has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Tweak javadoc for ValueLayout::arrayElementVarHandle

src/java.base/share/classes/java/lang/foreign/MemoryLayout.java line 374:

> 372:      *
> 373:      * Additionally, the provided dynamic values must conform to some bound which is derived from the layout path, that is,
> 374:      * {@code 0 <= x_i <= b_i}, where {@code 0 <= i <= n}, or {@link IndexOutOfBoundsException} is thrown.

Suggestion:

     * {@code 0 <= x_i < b_i}, where {@code 1 <= i <= n}, or {@link IndexOutOfBoundsException} is thrown.

We refer later to `B` being an exclusive upper bound (computed using `ceilDiv`).

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

PR: https://git.openjdk.java.net/jdk/pull/8868


More information about the core-libs-dev mailing list