RFR: 8287244: Add bound check in indexed memory access var handle [v2]
Paul Sandoz
psandoz at openjdk.java.net
Tue May 24 18:06:55 UTC 2022
On Tue, 24 May 2022 17:55:13 GMT, Paul Sandoz <psandoz at openjdk.org> wrote:
>> Here's a concrete example:
>>
>> Consider a sequence layout with 6 elements. Then:
>>
>> element count = 6
>> valid indices 0, 1, 2, 3, 4, 5
>>
>> Now consider a var handle that is obtained by calling the path element method, passing the following parameters
>>
>> start = 1
>> step = 2
>>
>> This sets up the following mapping between logical an physical indices:
>>
>> 0 -> 1
>> 1 -> 3
>> 2 -> 5
>>
>> Where on the LHS we have the logical index (the one passed to the VH) and on the RHS we have the actual index it is translated to.
>>
>> Note that the index map has three elements. So the upper bound (exclusive) of the index map is 3 - that is, we can pass indices 0, 1, 2.
>>
>> According to the formula shown in the javadoc:
>>
>> B = ceilDiv((elementCount - start) / step);
>>
>> so:
>>
>> B = ceilDiv((6 - 1) / 2)
>> = ceilDiv(5 / 2)
>>
>> Note how, w/o ceilDiv we'd get 2 (the last valid index), and not 3 (the first invalid index).
>
> The terms `x_1, x_2, ... x__n` are defined, but `x_0` is not.
>
> I think you can refer to the first index out of bounds as the exclusive upper bound of the range?
Sorry i misread the text, we are talking about the same thing. I think it would be clearer to refer `x_i` being in the range of `0` (inclusive) and `b_i` (exclusive), otherwise an .... is thrown. That way in subsequent doc on other methods in matches with `B`, which is exclusive.
-------------
PR: https://git.openjdk.java.net/jdk/pull/8868
More information about the core-libs-dev
mailing list