RFR: 8259925: [Vector API] Unreasonable IndexOutOfBoundsException message when length < vlen
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 , running script  and diff .
- For testSimple  that I checked last week, inlined if-statements  is better than Objects.checkIndex .
- However, for testLoop , Objects.checkIndex  is better than inlined if-statements .
(I'm sorry I didn't check loop methods last week.)
AFAICS, the inlined if-statements will generate two more instructions  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.
More information about the core-libs-dev