Description
The fast-range[1] algorithm:
https://lemire.me/blog/2016/06/27/a-fast-alternative-to-the-modulo-reduction/
It describes an efficient way to produce an index which is guaranteed to be inbounds:
for arbitrary non-negative (int) h and non-negative (int) size N, the ((long) h) * N) >>> 32 is less than N.
C2 can detect such pattern (by looking at how access index is computed) and skip bounds checks for it.
Relevant discussion:
https://mail.openjdk.java.net/pipermail/hotspot-dev/2019-November/040011.html
https://lemire.me/blog/2016/06/27/a-fast-alternative-to-the-modulo-reduction/
It describes an efficient way to produce an index which is guaranteed to be inbounds:
for arbitrary non-negative (int) h and non-negative (int) size N, the ((long) h) * N) >>> 32 is less than N.
C2 can detect such pattern (by looking at how access index is computed) and skip bounds checks for it.
Relevant discussion:
https://mail.openjdk.java.net/pipermail/hotspot-dev/2019-November/040011.html