JDK-8256730 : Code that uses Object.checkIndex() range checks doesn't optimize well
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 11,16
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2020-11-20
  • Updated: 2023-11-03
  • Resolved: 2020-12-10
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 16
16 b28Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Description
From Paul:

We have been investigating range check issues when using the Vector API. The recommended approach for loops is to express the upper bound using the method VectorSpecies.loopBound as in say:

@Benchmark
public float[] vector1() {
    int i = 0;
    for (; i < SPECIES.loopBound(a.length); i += SPECIES.length()) {
        // FloatVector va, vb, vc;
        var va = FloatVector.fromArray(SPECIES, a, i);
        var vb = FloatVector.fromArray(SPECIES, b, i);
        var vc = va.fma(va, vb.mul(vb)).neg();
        vc.intoArray(r, i);
    }

    for (; i < a.length; i++) {
        r[i] = Math.fma(a[i], a[i], b[i] * b[i]) * -1.0f;
    }

    return r;
}

However, this does not result in the removal of bounds checks from within the loop when loading/storing the vectors from/to memory.

Comments
Changeset: d93293f3 Author: Roland Westrelin <roland@openjdk.org> Date: 2020-12-10 08:09:08 +0000 URL: https://git.openjdk.java.net/jdk/commit/d93293f3
10-12-2020