Skip to content
This repository was archived by the owner on Sep 2, 2022. It is now read-only.
/ jdk17 Public archive

Commit 2b20778

Browse files
Xiaohong GongSandhya Viswanathan
authored andcommitted
8269568: JVM crashes when running VectorMask query tests
Co-authored-by: Sandhya Viswanathan <sviswanathan@openjdk.org> Reviewed-by: psandoz, jiefu, jbhateja, sviswanathan
1 parent 0f4e07b commit 2b20778

34 files changed

+1957
-807
lines changed

src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3894,6 +3894,9 @@ void C2_MacroAssembler::vector_mask_operation(int opc, Register dst, XMMRegister
38943894
vpxor(xtmp, xtmp, xtmp, vec_enc);
38953895
vpsubb(xtmp, xtmp, mask, vec_enc);
38963896
vpmovmskb(tmp, xtmp, vec_enc);
3897+
if (masklen < 64) {
3898+
andq(tmp, (((jlong)1 << masklen) - 1));
3899+
}
38973900
switch(opc) {
38983901
case Op_VectorMaskTrueCount:
38993902
popcntq(dst, tmp);

src/hotspot/share/opto/vectornode.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ class VectorMaskOpNode : public TypeNode {
876876
public:
877877
VectorMaskOpNode(Node* mask, const Type* ty, int mopc):
878878
TypeNode(ty, 2), _mopc(mopc) {
879-
assert(mask->Opcode() == Op_VectorStoreMask, "");
879+
assert(mask->bottom_type()->is_vect()->element_basic_type() == T_BOOLEAN, "");
880880
init_req(1, mask);
881881
}
882882

test/jdk/jdk/incubator/vector/Byte128VectorTests.java

Lines changed: 63 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,21 @@ static void assertReductionBoolArraysEquals(boolean[] r, boolean[] a, FBoolReduc
211211
}
212212
}
213213

214+
interface FMaskReductionOp {
215+
int apply(boolean[] a, int idx);
216+
}
217+
218+
static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReductionOp f) {
219+
int i = 0;
220+
try {
221+
for (; i < a.length; i += SPECIES.length()) {
222+
Assert.assertEquals(r[i], f.apply(a, i));
223+
}
224+
} catch (AssertionError e) {
225+
Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i);
226+
}
227+
}
228+
214229
static void assertInsertArraysEquals(byte[] r, byte[] a, byte element, int index) {
215230
int i = 0;
216231
try {
@@ -5230,55 +5245,77 @@ static void maskHashCodeByte128VectorTestsSmokeTest(IntFunction<boolean[]> fa) {
52305245
}
52315246
}
52325247

5248+
static int maskTrueCount(boolean[] a, int idx) {
5249+
int trueCount = 0;
5250+
for (int i = idx; i < idx + SPECIES.length(); i++) {
5251+
trueCount += a[i] ? 1 : 0;
5252+
}
5253+
return trueCount;
5254+
}
5255+
52335256
@Test(dataProvider = "maskProvider")
52345257
static void maskTrueCountByte128VectorTestsSmokeTest(IntFunction<boolean[]> fa) {
52355258
boolean[] a = fa.apply(SPECIES.length());
5259+
int[] r = new int[a.length];
52365260

5237-
for (int i = 0; i < a.length; i += SPECIES.length()) {
5238-
var vmask = SPECIES.loadMask(a, i);
5239-
int tcount = vmask.trueCount();
5240-
int expectedTcount = 0;
5241-
for (int j = i; j < i + SPECIES.length(); j++) {
5242-
expectedTcount += a[j] ? 1 : 0;
5261+
for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
5262+
for (int i = 0; i < a.length; i += SPECIES.length()) {
5263+
var vmask = SPECIES.loadMask(a, i);
5264+
r[i] = vmask.trueCount();
52435265
}
5244-
Assert.assertTrue(tcount == expectedTcount, "at index " + i + ", trueCount should be = " + expectedTcount + ", but is = " + tcount);
52455266
}
5267+
5268+
assertMaskReductionArraysEquals(r, a, Byte128VectorTests::maskTrueCount);
5269+
}
5270+
5271+
static int maskLastTrue(boolean[] a, int idx) {
5272+
int i = idx + SPECIES.length() - 1;
5273+
for (; i >= idx; i--) {
5274+
if (a[i]) {
5275+
break;
5276+
}
5277+
}
5278+
return i - idx;
52465279
}
52475280

52485281
@Test(dataProvider = "maskProvider")
52495282
static void maskLastTrueByte128VectorTestsSmokeTest(IntFunction<boolean[]> fa) {
52505283
boolean[] a = fa.apply(SPECIES.length());
5284+
int[] r = new int[a.length];
52515285

5252-
for (int i = 0; i < a.length; i += SPECIES.length()) {
5253-
var vmask = SPECIES.loadMask(a, i);
5254-
int ltrue = vmask.lastTrue();
5255-
int j = i + SPECIES.length() - 1;
5256-
for (; j >= i; j--) {
5257-
if (a[j]) break;
5286+
for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
5287+
for (int i = 0; i < a.length; i += SPECIES.length()) {
5288+
var vmask = SPECIES.loadMask(a, i);
5289+
r[i] = vmask.lastTrue();
52585290
}
5259-
int expectedLtrue = j - i;
5291+
}
52605292

5261-
Assert.assertTrue(ltrue == expectedLtrue, "at index " + i +
5262-
", lastTrue should be = " + expectedLtrue + ", but is = " + ltrue);
5293+
assertMaskReductionArraysEquals(r, a, Byte128VectorTests::maskLastTrue);
5294+
}
5295+
5296+
static int maskFirstTrue(boolean[] a, int idx) {
5297+
int i = idx;
5298+
for (; i < idx + SPECIES.length(); i++) {
5299+
if (a[i]) {
5300+
break;
5301+
}
52635302
}
5303+
return i - idx;
52645304
}
52655305

52665306
@Test(dataProvider = "maskProvider")
52675307
static void maskFirstTrueByte128VectorTestsSmokeTest(IntFunction<boolean[]> fa) {
52685308
boolean[] a = fa.apply(SPECIES.length());
5309+
int[] r = new int[a.length];
52695310

5270-
for (int i = 0; i < a.length; i += SPECIES.length()) {
5271-
var vmask = SPECIES.loadMask(a, i);
5272-
int ftrue = vmask.firstTrue();
5273-
int j = i;
5274-
for (; j < i + SPECIES.length() ; j++) {
5275-
if (a[j]) break;
5311+
for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
5312+
for (int i = 0; i < a.length; i += SPECIES.length()) {
5313+
var vmask = SPECIES.loadMask(a, i);
5314+
r[i] = vmask.firstTrue();
52765315
}
5277-
int expectedFtrue = j - i;
5278-
5279-
Assert.assertTrue(ftrue == expectedFtrue, "at index " + i +
5280-
", firstTrue should be = " + expectedFtrue + ", but is = " + ftrue);
52815316
}
5317+
5318+
assertMaskReductionArraysEquals(r, a, Byte128VectorTests::maskFirstTrue);
52825319
}
52835320

52845321
@DataProvider

test/jdk/jdk/incubator/vector/Byte256VectorTests.java

Lines changed: 63 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,21 @@ static void assertReductionBoolArraysEquals(boolean[] r, boolean[] a, FBoolReduc
211211
}
212212
}
213213

214+
interface FMaskReductionOp {
215+
int apply(boolean[] a, int idx);
216+
}
217+
218+
static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReductionOp f) {
219+
int i = 0;
220+
try {
221+
for (; i < a.length; i += SPECIES.length()) {
222+
Assert.assertEquals(r[i], f.apply(a, i));
223+
}
224+
} catch (AssertionError e) {
225+
Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i);
226+
}
227+
}
228+
214229
static void assertInsertArraysEquals(byte[] r, byte[] a, byte element, int index) {
215230
int i = 0;
216231
try {
@@ -5230,55 +5245,77 @@ static void maskHashCodeByte256VectorTestsSmokeTest(IntFunction<boolean[]> fa) {
52305245
}
52315246
}
52325247

5248+
static int maskTrueCount(boolean[] a, int idx) {
5249+
int trueCount = 0;
5250+
for (int i = idx; i < idx + SPECIES.length(); i++) {
5251+
trueCount += a[i] ? 1 : 0;
5252+
}
5253+
return trueCount;
5254+
}
5255+
52335256
@Test(dataProvider = "maskProvider")
52345257
static void maskTrueCountByte256VectorTestsSmokeTest(IntFunction<boolean[]> fa) {
52355258
boolean[] a = fa.apply(SPECIES.length());
5259+
int[] r = new int[a.length];
52365260

5237-
for (int i = 0; i < a.length; i += SPECIES.length()) {
5238-
var vmask = SPECIES.loadMask(a, i);
5239-
int tcount = vmask.trueCount();
5240-
int expectedTcount = 0;
5241-
for (int j = i; j < i + SPECIES.length(); j++) {
5242-
expectedTcount += a[j] ? 1 : 0;
5261+
for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
5262+
for (int i = 0; i < a.length; i += SPECIES.length()) {
5263+
var vmask = SPECIES.loadMask(a, i);
5264+
r[i] = vmask.trueCount();
52435265
}
5244-
Assert.assertTrue(tcount == expectedTcount, "at index " + i + ", trueCount should be = " + expectedTcount + ", but is = " + tcount);
52455266
}
5267+
5268+
assertMaskReductionArraysEquals(r, a, Byte256VectorTests::maskTrueCount);
5269+
}
5270+
5271+
static int maskLastTrue(boolean[] a, int idx) {
5272+
int i = idx + SPECIES.length() - 1;
5273+
for (; i >= idx; i--) {
5274+
if (a[i]) {
5275+
break;
5276+
}
5277+
}
5278+
return i - idx;
52465279
}
52475280

52485281
@Test(dataProvider = "maskProvider")
52495282
static void maskLastTrueByte256VectorTestsSmokeTest(IntFunction<boolean[]> fa) {
52505283
boolean[] a = fa.apply(SPECIES.length());
5284+
int[] r = new int[a.length];
52515285

5252-
for (int i = 0; i < a.length; i += SPECIES.length()) {
5253-
var vmask = SPECIES.loadMask(a, i);
5254-
int ltrue = vmask.lastTrue();
5255-
int j = i + SPECIES.length() - 1;
5256-
for (; j >= i; j--) {
5257-
if (a[j]) break;
5286+
for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
5287+
for (int i = 0; i < a.length; i += SPECIES.length()) {
5288+
var vmask = SPECIES.loadMask(a, i);
5289+
r[i] = vmask.lastTrue();
52585290
}
5259-
int expectedLtrue = j - i;
5291+
}
52605292

5261-
Assert.assertTrue(ltrue == expectedLtrue, "at index " + i +
5262-
", lastTrue should be = " + expectedLtrue + ", but is = " + ltrue);
5293+
assertMaskReductionArraysEquals(r, a, Byte256VectorTests::maskLastTrue);
5294+
}
5295+
5296+
static int maskFirstTrue(boolean[] a, int idx) {
5297+
int i = idx;
5298+
for (; i < idx + SPECIES.length(); i++) {
5299+
if (a[i]) {
5300+
break;
5301+
}
52635302
}
5303+
return i - idx;
52645304
}
52655305

52665306
@Test(dataProvider = "maskProvider")
52675307
static void maskFirstTrueByte256VectorTestsSmokeTest(IntFunction<boolean[]> fa) {
52685308
boolean[] a = fa.apply(SPECIES.length());
5309+
int[] r = new int[a.length];
52695310

5270-
for (int i = 0; i < a.length; i += SPECIES.length()) {
5271-
var vmask = SPECIES.loadMask(a, i);
5272-
int ftrue = vmask.firstTrue();
5273-
int j = i;
5274-
for (; j < i + SPECIES.length() ; j++) {
5275-
if (a[j]) break;
5311+
for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
5312+
for (int i = 0; i < a.length; i += SPECIES.length()) {
5313+
var vmask = SPECIES.loadMask(a, i);
5314+
r[i] = vmask.firstTrue();
52765315
}
5277-
int expectedFtrue = j - i;
5278-
5279-
Assert.assertTrue(ftrue == expectedFtrue, "at index " + i +
5280-
", firstTrue should be = " + expectedFtrue + ", but is = " + ftrue);
52815316
}
5317+
5318+
assertMaskReductionArraysEquals(r, a, Byte256VectorTests::maskFirstTrue);
52825319
}
52835320

52845321
@DataProvider

test/jdk/jdk/incubator/vector/Byte512VectorTests.java

Lines changed: 63 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,21 @@ static void assertReductionBoolArraysEquals(boolean[] r, boolean[] a, FBoolReduc
211211
}
212212
}
213213

214+
interface FMaskReductionOp {
215+
int apply(boolean[] a, int idx);
216+
}
217+
218+
static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReductionOp f) {
219+
int i = 0;
220+
try {
221+
for (; i < a.length; i += SPECIES.length()) {
222+
Assert.assertEquals(r[i], f.apply(a, i));
223+
}
224+
} catch (AssertionError e) {
225+
Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i);
226+
}
227+
}
228+
214229
static void assertInsertArraysEquals(byte[] r, byte[] a, byte element, int index) {
215230
int i = 0;
216231
try {
@@ -5230,55 +5245,77 @@ static void maskHashCodeByte512VectorTestsSmokeTest(IntFunction<boolean[]> fa) {
52305245
}
52315246
}
52325247

5248+
static int maskTrueCount(boolean[] a, int idx) {
5249+
int trueCount = 0;
5250+
for (int i = idx; i < idx + SPECIES.length(); i++) {
5251+
trueCount += a[i] ? 1 : 0;
5252+
}
5253+
return trueCount;
5254+
}
5255+
52335256
@Test(dataProvider = "maskProvider")
52345257
static void maskTrueCountByte512VectorTestsSmokeTest(IntFunction<boolean[]> fa) {
52355258
boolean[] a = fa.apply(SPECIES.length());
5259+
int[] r = new int[a.length];
52365260

5237-
for (int i = 0; i < a.length; i += SPECIES.length()) {
5238-
var vmask = SPECIES.loadMask(a, i);
5239-
int tcount = vmask.trueCount();
5240-
int expectedTcount = 0;
5241-
for (int j = i; j < i + SPECIES.length(); j++) {
5242-
expectedTcount += a[j] ? 1 : 0;
5261+
for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
5262+
for (int i = 0; i < a.length; i += SPECIES.length()) {
5263+
var vmask = SPECIES.loadMask(a, i);
5264+
r[i] = vmask.trueCount();
52435265
}
5244-
Assert.assertTrue(tcount == expectedTcount, "at index " + i + ", trueCount should be = " + expectedTcount + ", but is = " + tcount);
52455266
}
5267+
5268+
assertMaskReductionArraysEquals(r, a, Byte512VectorTests::maskTrueCount);
5269+
}
5270+
5271+
static int maskLastTrue(boolean[] a, int idx) {
5272+
int i = idx + SPECIES.length() - 1;
5273+
for (; i >= idx; i--) {
5274+
if (a[i]) {
5275+
break;
5276+
}
5277+
}
5278+
return i - idx;
52465279
}
52475280

52485281
@Test(dataProvider = "maskProvider")
52495282
static void maskLastTrueByte512VectorTestsSmokeTest(IntFunction<boolean[]> fa) {
52505283
boolean[] a = fa.apply(SPECIES.length());
5284+
int[] r = new int[a.length];
52515285

5252-
for (int i = 0; i < a.length; i += SPECIES.length()) {
5253-
var vmask = SPECIES.loadMask(a, i);
5254-
int ltrue = vmask.lastTrue();
5255-
int j = i + SPECIES.length() - 1;
5256-
for (; j >= i; j--) {
5257-
if (a[j]) break;
5286+
for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
5287+
for (int i = 0; i < a.length; i += SPECIES.length()) {
5288+
var vmask = SPECIES.loadMask(a, i);
5289+
r[i] = vmask.lastTrue();
52585290
}
5259-
int expectedLtrue = j - i;
5291+
}
52605292

5261-
Assert.assertTrue(ltrue == expectedLtrue, "at index " + i +
5262-
", lastTrue should be = " + expectedLtrue + ", but is = " + ltrue);
5293+
assertMaskReductionArraysEquals(r, a, Byte512VectorTests::maskLastTrue);
5294+
}
5295+
5296+
static int maskFirstTrue(boolean[] a, int idx) {
5297+
int i = idx;
5298+
for (; i < idx + SPECIES.length(); i++) {
5299+
if (a[i]) {
5300+
break;
5301+
}
52635302
}
5303+
return i - idx;
52645304
}
52655305

52665306
@Test(dataProvider = "maskProvider")
52675307
static void maskFirstTrueByte512VectorTestsSmokeTest(IntFunction<boolean[]> fa) {
52685308
boolean[] a = fa.apply(SPECIES.length());
5309+
int[] r = new int[a.length];
52695310

5270-
for (int i = 0; i < a.length; i += SPECIES.length()) {
5271-
var vmask = SPECIES.loadMask(a, i);
5272-
int ftrue = vmask.firstTrue();
5273-
int j = i;
5274-
for (; j < i + SPECIES.length() ; j++) {
5275-
if (a[j]) break;
5311+
for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
5312+
for (int i = 0; i < a.length; i += SPECIES.length()) {
5313+
var vmask = SPECIES.loadMask(a, i);
5314+
r[i] = vmask.firstTrue();
52765315
}
5277-
int expectedFtrue = j - i;
5278-
5279-
Assert.assertTrue(ftrue == expectedFtrue, "at index " + i +
5280-
", firstTrue should be = " + expectedFtrue + ", but is = " + ftrue);
52815316
}
5317+
5318+
assertMaskReductionArraysEquals(r, a, Byte512VectorTests::maskFirstTrue);
52825319
}
52835320

52845321
@DataProvider

0 commit comments

Comments
 (0)