mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8286279: [vectorapi] Only check index of masked lanes if offset is out of array boundary for masked store
Reviewed-by: psandoz
This commit is contained in:
parent
645be42f76
commit
ef7cc2105c
9 changed files with 216 additions and 37 deletions
|
@ -3008,7 +3008,7 @@ public abstract class ByteVector extends AbstractVector<Byte> {
|
|||
byte[] a, int offset,
|
||||
VectorMask<Byte> m) {
|
||||
ByteSpecies vsp = (ByteSpecies) species;
|
||||
if (offset >= 0 && offset <= (a.length - species.length())) {
|
||||
if (VectorIntrinsics.indexInRange(offset, vsp.length(), a.length)) {
|
||||
return vsp.dummyVector().fromArray0(a, offset, m);
|
||||
}
|
||||
|
||||
|
@ -3164,7 +3164,7 @@ public abstract class ByteVector extends AbstractVector<Byte> {
|
|||
boolean[] a, int offset,
|
||||
VectorMask<Byte> m) {
|
||||
ByteSpecies vsp = (ByteSpecies) species;
|
||||
if (offset >= 0 && offset <= (a.length - species.length())) {
|
||||
if (VectorIntrinsics.indexInRange(offset, vsp.length(), a.length)) {
|
||||
ByteVector zero = vsp.zero();
|
||||
return vsp.dummyVector().fromBooleanArray0(a, offset, m);
|
||||
}
|
||||
|
@ -3352,7 +3352,7 @@ public abstract class ByteVector extends AbstractVector<Byte> {
|
|||
ByteOrder bo,
|
||||
VectorMask<Byte> m) {
|
||||
ByteSpecies vsp = (ByteSpecies) species;
|
||||
if (offset >= 0 && offset <= (ms.byteSize() - species.vectorByteSize())) {
|
||||
if (VectorIntrinsics.indexInRange(offset, vsp.vectorByteSize(), ms.byteSize())) {
|
||||
return vsp.dummyVector().fromMemorySegment0(ms, offset, m).maybeSwap(bo);
|
||||
}
|
||||
|
||||
|
@ -3424,7 +3424,9 @@ public abstract class ByteVector extends AbstractVector<Byte> {
|
|||
intoArray(a, offset);
|
||||
} else {
|
||||
ByteSpecies vsp = vspecies();
|
||||
checkMaskFromIndexSize(offset, vsp, m, 1, a.length);
|
||||
if (!VectorIntrinsics.indexInRange(offset, vsp.length(), a.length)) {
|
||||
checkMaskFromIndexSize(offset, vsp, m, 1, a.length);
|
||||
}
|
||||
intoArray0(a, offset, m);
|
||||
}
|
||||
}
|
||||
|
@ -3579,7 +3581,9 @@ public abstract class ByteVector extends AbstractVector<Byte> {
|
|||
intoBooleanArray(a, offset);
|
||||
} else {
|
||||
ByteSpecies vsp = vspecies();
|
||||
checkMaskFromIndexSize(offset, vsp, m, 1, a.length);
|
||||
if (!VectorIntrinsics.indexInRange(offset, vsp.length(), a.length)) {
|
||||
checkMaskFromIndexSize(offset, vsp, m, 1, a.length);
|
||||
}
|
||||
intoBooleanArray0(a, offset, m);
|
||||
}
|
||||
}
|
||||
|
@ -3709,7 +3713,9 @@ public abstract class ByteVector extends AbstractVector<Byte> {
|
|||
throw new UnsupportedOperationException("Attempt to write a read-only segment");
|
||||
}
|
||||
ByteSpecies vsp = vspecies();
|
||||
checkMaskFromIndexSize(offset, vsp, m, 1, ms.byteSize());
|
||||
if (!VectorIntrinsics.indexInRange(offset, vsp.vectorByteSize(), ms.byteSize())) {
|
||||
checkMaskFromIndexSize(offset, vsp, m, 1, ms.byteSize());
|
||||
}
|
||||
maybeSwap(bo).intoMemorySegment0(ms, offset, m);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2805,7 +2805,7 @@ public abstract class DoubleVector extends AbstractVector<Double> {
|
|||
double[] a, int offset,
|
||||
VectorMask<Double> m) {
|
||||
DoubleSpecies vsp = (DoubleSpecies) species;
|
||||
if (offset >= 0 && offset <= (a.length - species.length())) {
|
||||
if (VectorIntrinsics.indexInRange(offset, vsp.length(), a.length)) {
|
||||
return vsp.dummyVector().fromArray0(a, offset, m);
|
||||
}
|
||||
|
||||
|
@ -3038,7 +3038,7 @@ public abstract class DoubleVector extends AbstractVector<Double> {
|
|||
ByteOrder bo,
|
||||
VectorMask<Double> m) {
|
||||
DoubleSpecies vsp = (DoubleSpecies) species;
|
||||
if (offset >= 0 && offset <= (ms.byteSize() - species.vectorByteSize())) {
|
||||
if (VectorIntrinsics.indexInRange(offset, vsp.vectorByteSize(), ms.byteSize())) {
|
||||
return vsp.dummyVector().fromMemorySegment0(ms, offset, m).maybeSwap(bo);
|
||||
}
|
||||
|
||||
|
@ -3110,7 +3110,9 @@ public abstract class DoubleVector extends AbstractVector<Double> {
|
|||
intoArray(a, offset);
|
||||
} else {
|
||||
DoubleSpecies vsp = vspecies();
|
||||
checkMaskFromIndexSize(offset, vsp, m, 1, a.length);
|
||||
if (!VectorIntrinsics.indexInRange(offset, vsp.length(), a.length)) {
|
||||
checkMaskFromIndexSize(offset, vsp, m, 1, a.length);
|
||||
}
|
||||
intoArray0(a, offset, m);
|
||||
}
|
||||
}
|
||||
|
@ -3266,7 +3268,9 @@ public abstract class DoubleVector extends AbstractVector<Double> {
|
|||
throw new UnsupportedOperationException("Attempt to write a read-only segment");
|
||||
}
|
||||
DoubleSpecies vsp = vspecies();
|
||||
checkMaskFromIndexSize(offset, vsp, m, 8, ms.byteSize());
|
||||
if (!VectorIntrinsics.indexInRange(offset, vsp.vectorByteSize(), ms.byteSize())) {
|
||||
checkMaskFromIndexSize(offset, vsp, m, 8, ms.byteSize());
|
||||
}
|
||||
maybeSwap(bo).intoMemorySegment0(ms, offset, m);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2829,7 +2829,7 @@ public abstract class FloatVector extends AbstractVector<Float> {
|
|||
float[] a, int offset,
|
||||
VectorMask<Float> m) {
|
||||
FloatSpecies vsp = (FloatSpecies) species;
|
||||
if (offset >= 0 && offset <= (a.length - species.length())) {
|
||||
if (VectorIntrinsics.indexInRange(offset, vsp.length(), a.length)) {
|
||||
return vsp.dummyVector().fromArray0(a, offset, m);
|
||||
}
|
||||
|
||||
|
@ -3044,7 +3044,7 @@ public abstract class FloatVector extends AbstractVector<Float> {
|
|||
ByteOrder bo,
|
||||
VectorMask<Float> m) {
|
||||
FloatSpecies vsp = (FloatSpecies) species;
|
||||
if (offset >= 0 && offset <= (ms.byteSize() - species.vectorByteSize())) {
|
||||
if (VectorIntrinsics.indexInRange(offset, vsp.vectorByteSize(), ms.byteSize())) {
|
||||
return vsp.dummyVector().fromMemorySegment0(ms, offset, m).maybeSwap(bo);
|
||||
}
|
||||
|
||||
|
@ -3116,7 +3116,9 @@ public abstract class FloatVector extends AbstractVector<Float> {
|
|||
intoArray(a, offset);
|
||||
} else {
|
||||
FloatSpecies vsp = vspecies();
|
||||
checkMaskFromIndexSize(offset, vsp, m, 1, a.length);
|
||||
if (!VectorIntrinsics.indexInRange(offset, vsp.length(), a.length)) {
|
||||
checkMaskFromIndexSize(offset, vsp, m, 1, a.length);
|
||||
}
|
||||
intoArray0(a, offset, m);
|
||||
}
|
||||
}
|
||||
|
@ -3253,7 +3255,9 @@ public abstract class FloatVector extends AbstractVector<Float> {
|
|||
throw new UnsupportedOperationException("Attempt to write a read-only segment");
|
||||
}
|
||||
FloatSpecies vsp = vspecies();
|
||||
checkMaskFromIndexSize(offset, vsp, m, 4, ms.byteSize());
|
||||
if (!VectorIntrinsics.indexInRange(offset, vsp.vectorByteSize(), ms.byteSize())) {
|
||||
checkMaskFromIndexSize(offset, vsp, m, 4, ms.byteSize());
|
||||
}
|
||||
maybeSwap(bo).intoMemorySegment0(ms, offset, m);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2986,7 +2986,7 @@ public abstract class IntVector extends AbstractVector<Integer> {
|
|||
int[] a, int offset,
|
||||
VectorMask<Integer> m) {
|
||||
IntSpecies vsp = (IntSpecies) species;
|
||||
if (offset >= 0 && offset <= (a.length - species.length())) {
|
||||
if (VectorIntrinsics.indexInRange(offset, vsp.length(), a.length)) {
|
||||
return vsp.dummyVector().fromArray0(a, offset, m);
|
||||
}
|
||||
|
||||
|
@ -3201,7 +3201,7 @@ public abstract class IntVector extends AbstractVector<Integer> {
|
|||
ByteOrder bo,
|
||||
VectorMask<Integer> m) {
|
||||
IntSpecies vsp = (IntSpecies) species;
|
||||
if (offset >= 0 && offset <= (ms.byteSize() - species.vectorByteSize())) {
|
||||
if (VectorIntrinsics.indexInRange(offset, vsp.vectorByteSize(), ms.byteSize())) {
|
||||
return vsp.dummyVector().fromMemorySegment0(ms, offset, m).maybeSwap(bo);
|
||||
}
|
||||
|
||||
|
@ -3273,7 +3273,9 @@ public abstract class IntVector extends AbstractVector<Integer> {
|
|||
intoArray(a, offset);
|
||||
} else {
|
||||
IntSpecies vsp = vspecies();
|
||||
checkMaskFromIndexSize(offset, vsp, m, 1, a.length);
|
||||
if (!VectorIntrinsics.indexInRange(offset, vsp.length(), a.length)) {
|
||||
checkMaskFromIndexSize(offset, vsp, m, 1, a.length);
|
||||
}
|
||||
intoArray0(a, offset, m);
|
||||
}
|
||||
}
|
||||
|
@ -3410,7 +3412,9 @@ public abstract class IntVector extends AbstractVector<Integer> {
|
|||
throw new UnsupportedOperationException("Attempt to write a read-only segment");
|
||||
}
|
||||
IntSpecies vsp = vspecies();
|
||||
checkMaskFromIndexSize(offset, vsp, m, 4, ms.byteSize());
|
||||
if (!VectorIntrinsics.indexInRange(offset, vsp.vectorByteSize(), ms.byteSize())) {
|
||||
checkMaskFromIndexSize(offset, vsp, m, 4, ms.byteSize());
|
||||
}
|
||||
maybeSwap(bo).intoMemorySegment0(ms, offset, m);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2847,7 +2847,7 @@ public abstract class LongVector extends AbstractVector<Long> {
|
|||
long[] a, int offset,
|
||||
VectorMask<Long> m) {
|
||||
LongSpecies vsp = (LongSpecies) species;
|
||||
if (offset >= 0 && offset <= (a.length - species.length())) {
|
||||
if (VectorIntrinsics.indexInRange(offset, vsp.length(), a.length)) {
|
||||
return vsp.dummyVector().fromArray0(a, offset, m);
|
||||
}
|
||||
|
||||
|
@ -3080,7 +3080,7 @@ public abstract class LongVector extends AbstractVector<Long> {
|
|||
ByteOrder bo,
|
||||
VectorMask<Long> m) {
|
||||
LongSpecies vsp = (LongSpecies) species;
|
||||
if (offset >= 0 && offset <= (ms.byteSize() - species.vectorByteSize())) {
|
||||
if (VectorIntrinsics.indexInRange(offset, vsp.vectorByteSize(), ms.byteSize())) {
|
||||
return vsp.dummyVector().fromMemorySegment0(ms, offset, m).maybeSwap(bo);
|
||||
}
|
||||
|
||||
|
@ -3152,7 +3152,9 @@ public abstract class LongVector extends AbstractVector<Long> {
|
|||
intoArray(a, offset);
|
||||
} else {
|
||||
LongSpecies vsp = vspecies();
|
||||
checkMaskFromIndexSize(offset, vsp, m, 1, a.length);
|
||||
if (!VectorIntrinsics.indexInRange(offset, vsp.length(), a.length)) {
|
||||
checkMaskFromIndexSize(offset, vsp, m, 1, a.length);
|
||||
}
|
||||
intoArray0(a, offset, m);
|
||||
}
|
||||
}
|
||||
|
@ -3308,7 +3310,9 @@ public abstract class LongVector extends AbstractVector<Long> {
|
|||
throw new UnsupportedOperationException("Attempt to write a read-only segment");
|
||||
}
|
||||
LongSpecies vsp = vspecies();
|
||||
checkMaskFromIndexSize(offset, vsp, m, 8, ms.byteSize());
|
||||
if (!VectorIntrinsics.indexInRange(offset, vsp.vectorByteSize(), ms.byteSize())) {
|
||||
checkMaskFromIndexSize(offset, vsp, m, 8, ms.byteSize());
|
||||
}
|
||||
maybeSwap(bo).intoMemorySegment0(ms, offset, m);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3009,7 +3009,7 @@ public abstract class ShortVector extends AbstractVector<Short> {
|
|||
short[] a, int offset,
|
||||
VectorMask<Short> m) {
|
||||
ShortSpecies vsp = (ShortSpecies) species;
|
||||
if (offset >= 0 && offset <= (a.length - species.length())) {
|
||||
if (VectorIntrinsics.indexInRange(offset, vsp.length(), a.length)) {
|
||||
return vsp.dummyVector().fromArray0(a, offset, m);
|
||||
}
|
||||
|
||||
|
@ -3158,7 +3158,7 @@ public abstract class ShortVector extends AbstractVector<Short> {
|
|||
char[] a, int offset,
|
||||
VectorMask<Short> m) {
|
||||
ShortSpecies vsp = (ShortSpecies) species;
|
||||
if (offset >= 0 && offset <= (a.length - species.length())) {
|
||||
if (VectorIntrinsics.indexInRange(offset, vsp.length(), a.length)) {
|
||||
return vsp.dummyVector().fromCharArray0(a, offset, m);
|
||||
}
|
||||
|
||||
|
@ -3351,7 +3351,7 @@ public abstract class ShortVector extends AbstractVector<Short> {
|
|||
ByteOrder bo,
|
||||
VectorMask<Short> m) {
|
||||
ShortSpecies vsp = (ShortSpecies) species;
|
||||
if (offset >= 0 && offset <= (ms.byteSize() - species.vectorByteSize())) {
|
||||
if (VectorIntrinsics.indexInRange(offset, vsp.vectorByteSize(), ms.byteSize())) {
|
||||
return vsp.dummyVector().fromMemorySegment0(ms, offset, m).maybeSwap(bo);
|
||||
}
|
||||
|
||||
|
@ -3423,7 +3423,9 @@ public abstract class ShortVector extends AbstractVector<Short> {
|
|||
intoArray(a, offset);
|
||||
} else {
|
||||
ShortSpecies vsp = vspecies();
|
||||
checkMaskFromIndexSize(offset, vsp, m, 1, a.length);
|
||||
if (!VectorIntrinsics.indexInRange(offset, vsp.length(), a.length)) {
|
||||
checkMaskFromIndexSize(offset, vsp, m, 1, a.length);
|
||||
}
|
||||
intoArray0(a, offset, m);
|
||||
}
|
||||
}
|
||||
|
@ -3570,7 +3572,9 @@ public abstract class ShortVector extends AbstractVector<Short> {
|
|||
intoCharArray(a, offset);
|
||||
} else {
|
||||
ShortSpecies vsp = vspecies();
|
||||
checkMaskFromIndexSize(offset, vsp, m, 1, a.length);
|
||||
if (!VectorIntrinsics.indexInRange(offset, vsp.length(), a.length)) {
|
||||
checkMaskFromIndexSize(offset, vsp, m, 1, a.length);
|
||||
}
|
||||
intoCharArray0(a, offset, m);
|
||||
}
|
||||
}
|
||||
|
@ -3695,7 +3699,9 @@ public abstract class ShortVector extends AbstractVector<Short> {
|
|||
throw new UnsupportedOperationException("Attempt to write a read-only segment");
|
||||
}
|
||||
ShortSpecies vsp = vspecies();
|
||||
checkMaskFromIndexSize(offset, vsp, m, 2, ms.byteSize());
|
||||
if (!VectorIntrinsics.indexInRange(offset, vsp.vectorByteSize(), ms.byteSize())) {
|
||||
checkMaskFromIndexSize(offset, vsp, m, 2, ms.byteSize());
|
||||
}
|
||||
maybeSwap(bo).intoMemorySegment0(ms, offset, m);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -44,6 +44,11 @@ import java.util.Objects;
|
|||
return new IllegalArgumentException(msg);
|
||||
}
|
||||
|
||||
@ForceInline
|
||||
static boolean indexInRange(long ix, long vlen, long length) {
|
||||
return ix >= 0 && ix <= (length - vlen);
|
||||
}
|
||||
|
||||
@ForceInline
|
||||
static int checkFromIndexSize(int ix, int vlen, int length) {
|
||||
switch (VectorIntrinsics.VECTOR_ACCESS_OOB_CHECK) {
|
||||
|
|
|
@ -3583,7 +3583,7 @@ public abstract class $abstractvectortype$ extends AbstractVector<$Boxtype$> {
|
|||
$type$[] a, int offset,
|
||||
VectorMask<$Boxtype$> m) {
|
||||
$Type$Species vsp = ($Type$Species) species;
|
||||
if (offset >= 0 && offset <= (a.length - species.length())) {
|
||||
if (VectorIntrinsics.indexInRange(offset, vsp.length(), a.length)) {
|
||||
return vsp.dummyVector().fromArray0(a, offset, m);
|
||||
}
|
||||
|
||||
|
@ -3804,7 +3804,7 @@ public abstract class $abstractvectortype$ extends AbstractVector<$Boxtype$> {
|
|||
char[] a, int offset,
|
||||
VectorMask<$Boxtype$> m) {
|
||||
$Type$Species vsp = ($Type$Species) species;
|
||||
if (offset >= 0 && offset <= (a.length - species.length())) {
|
||||
if (VectorIntrinsics.indexInRange(offset, vsp.length(), a.length)) {
|
||||
return vsp.dummyVector().fromCharArray0(a, offset, m);
|
||||
}
|
||||
|
||||
|
@ -3963,7 +3963,7 @@ public abstract class $abstractvectortype$ extends AbstractVector<$Boxtype$> {
|
|||
boolean[] a, int offset,
|
||||
VectorMask<$Boxtype$> m) {
|
||||
$Type$Species vsp = ($Type$Species) species;
|
||||
if (offset >= 0 && offset <= (a.length - species.length())) {
|
||||
if (VectorIntrinsics.indexInRange(offset, vsp.length(), a.length)) {
|
||||
$abstractvectortype$ zero = vsp.zero();
|
||||
return vsp.dummyVector().fromBooleanArray0(a, offset, m);
|
||||
}
|
||||
|
@ -4161,7 +4161,7 @@ public abstract class $abstractvectortype$ extends AbstractVector<$Boxtype$> {
|
|||
ByteOrder bo,
|
||||
VectorMask<$Boxtype$> m) {
|
||||
$Type$Species vsp = ($Type$Species) species;
|
||||
if (offset >= 0 && offset <= (ms.byteSize() - species.vectorByteSize())) {
|
||||
if (VectorIntrinsics.indexInRange(offset, vsp.vectorByteSize(), ms.byteSize())) {
|
||||
return vsp.dummyVector().fromMemorySegment0(ms, offset, m).maybeSwap(bo);
|
||||
}
|
||||
|
||||
|
@ -4233,7 +4233,9 @@ public abstract class $abstractvectortype$ extends AbstractVector<$Boxtype$> {
|
|||
intoArray(a, offset);
|
||||
} else {
|
||||
$Type$Species vsp = vspecies();
|
||||
checkMaskFromIndexSize(offset, vsp, m, 1, a.length);
|
||||
if (!VectorIntrinsics.indexInRange(offset, vsp.length(), a.length)) {
|
||||
checkMaskFromIndexSize(offset, vsp, m, 1, a.length);
|
||||
}
|
||||
intoArray0(a, offset, m);
|
||||
}
|
||||
}
|
||||
|
@ -4451,7 +4453,9 @@ public abstract class $abstractvectortype$ extends AbstractVector<$Boxtype$> {
|
|||
intoCharArray(a, offset);
|
||||
} else {
|
||||
$Type$Species vsp = vspecies();
|
||||
checkMaskFromIndexSize(offset, vsp, m, 1, a.length);
|
||||
if (!VectorIntrinsics.indexInRange(offset, vsp.length(), a.length)) {
|
||||
checkMaskFromIndexSize(offset, vsp, m, 1, a.length);
|
||||
}
|
||||
intoCharArray0(a, offset, m);
|
||||
}
|
||||
}
|
||||
|
@ -4613,7 +4617,9 @@ public abstract class $abstractvectortype$ extends AbstractVector<$Boxtype$> {
|
|||
intoBooleanArray(a, offset);
|
||||
} else {
|
||||
$Type$Species vsp = vspecies();
|
||||
checkMaskFromIndexSize(offset, vsp, m, 1, a.length);
|
||||
if (!VectorIntrinsics.indexInRange(offset, vsp.length(), a.length)) {
|
||||
checkMaskFromIndexSize(offset, vsp, m, 1, a.length);
|
||||
}
|
||||
intoBooleanArray0(a, offset, m);
|
||||
}
|
||||
}
|
||||
|
@ -4744,7 +4750,9 @@ public abstract class $abstractvectortype$ extends AbstractVector<$Boxtype$> {
|
|||
throw new UnsupportedOperationException("Attempt to write a read-only segment");
|
||||
}
|
||||
$Type$Species vsp = vspecies();
|
||||
checkMaskFromIndexSize(offset, vsp, m, $sizeInBytes$, ms.byteSize());
|
||||
if (!VectorIntrinsics.indexInRange(offset, vsp.vectorByteSize(), ms.byteSize())) {
|
||||
checkMaskFromIndexSize(offset, vsp, m, $sizeInBytes$, ms.byteSize());
|
||||
}
|
||||
maybeSwap(bo).intoMemorySegment0(ms, offset, m);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue