RFR: 8259925: [Vector API] Unreasonable IndexOutOfBoundsException message when length < vlen

Paul Sandoz psandoz at openjdk.java.net
Wed Jan 20 19:33:50 UTC 2021

On Wed, 20 Jan 2021 09:33:43 GMT, Jie Fu <jiefu at openjdk.org> wrote:

>> That change may cause performance issues. I would recommend leaving as is for now even through the error message is not great. Bounds checking is quite sensitive and WIP. Notice that we also have an option to call `Objects.checkFromIndexSize` which expresses the intent more accurately, but that is currently less optimal (at least it was when i last checked since it is non an intrinsic).
> Thanks @PaulSandoz for your review and comments.
> Updated:
>  - The performance issue has been fixed since there is no more operation for common cases.
>  - The readability of OOB exception msg has been improved by following the style of Objects.checkFromIndexSize.
>  - Less code generated (several blocks of code were optimized out for the Test::test method below).
> import jdk.incubator.vector.ByteVector;
> import jdk.incubator.vector.VectorSpecies;
> public class Test {
>     static final VectorSpecies<Byte> SPECIES_128 = ByteVector.SPECIES_128;
>     static byte[] a = new byte[88];
>     static byte[] b = new byte[88];
>     public static void test() {
>         ByteVector av = ByteVector.fromArray(SPECIES_128, a, 0);
>         av.intoArray(b, 0);
>     }
>     public static void main(String[] args) {
>         for (int i = 0; i < 100000; i++) {
>             test();
>         }
>         System.out.println("b: " + b[0]);
>     }
> }
> What do you think of it?
> Thanks.

Unfortunately it is still problematic because you have replaced the intrinsic check (that performed by `Object.checksIndex`, or more specifically [here](https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/jdk/internal/util/Preconditions.java#L261)).

Further, you have replaced the bounds check options, in place for experimentation. We are not ready yet to collapse our options, further analysis is required as bounds checks can be very sensitive in C2.

I would be open to you adding a third case, so that you can analyze the performance without perturbing the default behavior. I suspect the correct fix is to make intrinsic `Objects.checkFromIndexSize` in a similar manner to `Object.checksIndex`.


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

More information about the core-libs-dev mailing list