JDK-8326664 : Gather index checking under mask
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 18,21,22,23
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: generic
  • CPU: generic
  • Submitted: 2024-02-26
  • Updated: 2024-03-04
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.
Other
tbdUnresolved
Related Reports
Relates :  
Relates :  
Description
Currently, gather index out of bounds checking is agnostic to existence of masks, thus an index value is compared against array bounds even if its corresponding mask bit is false.

Look for following FIXME.

https://github.com/openjdk/jdk/blob/master/src/jdk.incubator.vector/share/classes/jdk/incubator/vector/X-Vector.java.template#L4845


Comments
Okay, thanks for the details, [~jbhateja]. Initial-ILW = Incorrect IndexOutOfBoundsException thrown (too strict), with Vector API (Incubator), no workaround = MLH = P4
04-03-2024

For sub-word gathers, we should add a new checkIndex routine on following lines checkIndex(int [] indices, int alength, VectorMask<Byte> mask) { long lmask = mask.toLong(); for (int i = 0, j = 0; i < indices.length; i += S512.length()) { var ivec = IntVector.fromArray(S512, indices, i); if (ivec.compare(VectorOperators.LT, 0) .or(ivec.compare(VectorOperators.GT, alength) .and(VectorMask.fromLong(S512, lmask >> (16 * j++)))) .anyTrue()) { throw new IndexOutOfBoundsException(); } }
02-03-2024

[~thartmann] This is bug, please consider follow jshell command sequence.. jshell> import jdk.incubator.vector.* jshell> import java.util.stream.IntStream jshell> int [] mem = IntStream.range(0, 1024).toArray() mem ==> int[1024] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... , 1020, 1021, 1022, 1023 } jshell> int [] indices = {0, 20, 40, 2048, 80, 100, 120, 140} indices ==> int[8] { 0, 20, 40, 2048, 80, 100, 120, 140 } jshell> var gvec = IntVector.fromArray(IntVector.SPECIES_256, mem, 0, indices, 0, VectorMask.fromLong(IntVector.SPECIES_256, 0xF0)) | Exception java.lang.IndexOutOfBoundsException: Range check failed: vector [0, 20, 40, 2048, 80, 100, 120, 140] out of bounds for length 1024 | at VectorIntrinsics.checkIndexFailed (VectorIntrinsics.java:95) | at VectorIntrinsics.checkIndex (VectorIntrinsics.java:85) | at IntVector.fromArray0Template (IntVector.java:3490) | at Int256Vector.fromArray0 (Int256Vector.java:874) | at IntVector.fromArray (IntVector.java:3098) | at do_it$Aux (#5:1) | at (#5:1) Even though out of bound index is masked out we receive an IOOB exception.
02-03-2024

[~jbhateja] I assume this is rather an enhancement than a bug? Converting to enhancement for now.
27-02-2024