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

Jie Fu jiefu at openjdk.java.net
Tue Jan 26 13:27:40 UTC 2021

On Thu, 21 Jan 2021 16:54:36 GMT, Paul Sandoz <psandoz at openjdk.org> wrote:

> The intrinsic enables C2 to more reliably elide bounds checks. I don't know the exact details but at a high-level it transforms signed values into unsigned values (and therefore the signed comparisons become unsigned comparisons), which helps C2 remove checks when there is a dominating check of, for example, an upper loop bound.
> You say "the intrinsified Objects.checkIndex seems to generate more code than inlined if-statements". Can you present some examples of Java code and the corresponding C2 generated assembler where this happens?

Hi @PaulSandoz ,

I agree with you that let's keep the code as it is for the sake of performance.

I spent some time looking into the assembly code generated by Objects.checkIndex and inlined if-statements.
Here are the test program [1], running script [2] and diff [3].

 - For testSimple [4] that I checked last week, inlined if-statements [5] is better than Objects.checkIndex [6].
 - However, for testLoop [7], Objects.checkIndex [8] is better than inlined if-statements [9].
   (I'm sorry I didn't check loop methods last week.)
   AFAICS, the inlined if-statements will generate two more instructions [10] to check wether idx >= 0 for each loop iteration.

It seems that the intrinsified Objects.checkIndex will be able to optimize out the lower bound check for loops.
So I also agree with you that an intrinsified method seems the right choice.

Best regards,

[1] https://github.com/DamonFool/experiment/blob/main/JDK-8259925/Bar.java
[2] https://github.com/DamonFool/experiment/blob/main/JDK-8259925/1.sh
[3] https://github.com/DamonFool/experiment/blob/main/JDK-8259925/1.diff
[4] https://github.com/DamonFool/experiment/blob/main/JDK-8259925/Bar.java#L10
[5] https://github.com/DamonFool/experiment/blob/main/JDK-8259925/3-testSimple.log
[6] https://github.com/DamonFool/experiment/blob/main/JDK-8259925/2-testSimple.log
[7] https://github.com/DamonFool/experiment/blob/main/JDK-8259925/Bar.java#L15
[8] https://github.com/DamonFool/experiment/blob/main/JDK-8259925/2-testLoop.log
[9] https://github.com/DamonFool/experiment/blob/main/JDK-8259925/3-testLoop.log
[10] https://github.com/DamonFool/experiment/blob/main/JDK-8259925/3-testLoop.log#L135


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

More information about the core-libs-dev mailing list