< prev index next >
src/jdk.incubator.vector/share/classes/jdk/incubator/vector/ShortVector.java
Print this page
rev 55589 : 8221816: [vector] IndexOutOfBoundsException for fromArray/intoArray with unset mask lanes
Reviewed-by: duke
@@ -194,21 +194,25 @@
* @return the vector loaded from an array
* @throws IndexOutOfBoundsException if {@code i < 0}, or
* {@code i > a.length - this.length()}
*/
@ForceInline
- @SuppressWarnings("unchecked")
- public static ShortVector fromArray(ShortSpecies species, short[] a, int i){
+ public static ShortVector fromArray(ShortSpecies species, short[] a, int i) {
Objects.requireNonNull(a);
i = VectorIntrinsics.checkIndex(i, a.length, species.length());
+ return fromArrayWithoutCheck(species, a, i);
+ }
+
+ @ForceInline
+ @SuppressWarnings("unchecked")
+ static ShortVector fromArrayWithoutCheck(ShortSpecies species, short[] a, int i) {
return VectorIntrinsics.load((Class<ShortVector>) species.boxType(), short.class, species.length(),
a, (((long) i) << ARRAY_SHIFT) + Unsafe.ARRAY_SHORT_BASE_OFFSET,
a, i, species,
(c, idx, s) -> ((ShortSpecies)s).op(n -> c[idx + n]));
}
-
/**
* Loads a vector from an array starting at offset and using a mask.
* <p>
* For each vector lane, where {@code N} is the vector lane index,
* if the mask lane at index {@code N} is set then the array element at
@@ -225,11 +229,16 @@
* for any vector lane index {@code N} where the mask at lane {@code N}
* is set {@code i > a.length - N}
*/
@ForceInline
public static ShortVector fromArray(ShortSpecies species, short[] a, int i, Mask<Short> m) {
- return zero(species).blend(fromArray(species, a, i), m);
+ Objects.requireNonNull(a);
+ if (i + species.length() <= a.length) {
+ return zero(species).blend(fromArrayWithoutCheck(species, a, i), m);
+ } else {
+ return species.op(m, n -> a[i + n]);
+ }
}
/**
* Loads a vector from an array using indexes obtained from an index
* map.
@@ -252,10 +261,11 @@
* {@code i + indexMap[j + N]} is {@code < 0} or {@code >= a.length}
*/
public static ShortVector fromArray(ShortSpecies species, short[] a, int i, int[] indexMap, int j) {
return species.op(n -> a[i + indexMap[j + n]]);
}
+
/**
* Loads a vector from an array using indexes obtained from an index
* map and using a mask.
* <p>
* For each vector lane, where {@code N} is the vector lane index,
< prev index next >