Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.

Commit

Permalink
8269568: JVM crashes when running VectorMask query tests
Browse files Browse the repository at this point in the history
Co-authored-by: Sandhya Viswanathan <sviswanathan@openjdk.org>
Reviewed-by: psandoz, jiefu, jbhateja, sviswanathan
  • Loading branch information
2 people authored and DamonFool committed Jul 6, 2021
1 parent 0f4e07b commit 2b20778
Show file tree
Hide file tree
Showing 34 changed files with 1,957 additions and 807 deletions.
3 changes: 3 additions & 0 deletions src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp
Expand Up @@ -3894,6 +3894,9 @@ void C2_MacroAssembler::vector_mask_operation(int opc, Register dst, XMMRegister
vpxor(xtmp, xtmp, xtmp, vec_enc);
vpsubb(xtmp, xtmp, mask, vec_enc);
vpmovmskb(tmp, xtmp, vec_enc);
if (masklen < 64) {
andq(tmp, (((jlong)1 << masklen) - 1));
}
switch(opc) {
case Op_VectorMaskTrueCount:
popcntq(dst, tmp);
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/opto/vectornode.hpp
Expand Up @@ -876,7 +876,7 @@ class VectorMaskOpNode : public TypeNode {
public:
VectorMaskOpNode(Node* mask, const Type* ty, int mopc):
TypeNode(ty, 2), _mopc(mopc) {
assert(mask->Opcode() == Op_VectorStoreMask, "");
assert(mask->bottom_type()->is_vect()->element_basic_type() == T_BOOLEAN, "");
init_req(1, mask);
}

Expand Down
89 changes: 63 additions & 26 deletions test/jdk/jdk/incubator/vector/Byte128VectorTests.java
Expand Up @@ -211,6 +211,21 @@ static void assertReductionBoolArraysEquals(boolean[] r, boolean[] a, FBoolReduc
}
}

interface FMaskReductionOp {
int apply(boolean[] a, int idx);
}

static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReductionOp f) {
int i = 0;
try {
for (; i < a.length; i += SPECIES.length()) {
Assert.assertEquals(r[i], f.apply(a, i));
}
} catch (AssertionError e) {
Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i);
}
}

static void assertInsertArraysEquals(byte[] r, byte[] a, byte element, int index) {
int i = 0;
try {
Expand Down Expand Up @@ -5230,55 +5245,77 @@ static void maskHashCodeByte128VectorTestsSmokeTest(IntFunction<boolean[]> fa) {
}
}

static int maskTrueCount(boolean[] a, int idx) {
int trueCount = 0;
for (int i = idx; i < idx + SPECIES.length(); i++) {
trueCount += a[i] ? 1 : 0;
}
return trueCount;
}

@Test(dataProvider = "maskProvider")
static void maskTrueCountByte128VectorTestsSmokeTest(IntFunction<boolean[]> fa) {
boolean[] a = fa.apply(SPECIES.length());
int[] r = new int[a.length];

for (int i = 0; i < a.length; i += SPECIES.length()) {
var vmask = SPECIES.loadMask(a, i);
int tcount = vmask.trueCount();
int expectedTcount = 0;
for (int j = i; j < i + SPECIES.length(); j++) {
expectedTcount += a[j] ? 1 : 0;
for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
for (int i = 0; i < a.length; i += SPECIES.length()) {
var vmask = SPECIES.loadMask(a, i);
r[i] = vmask.trueCount();
}
Assert.assertTrue(tcount == expectedTcount, "at index " + i + ", trueCount should be = " + expectedTcount + ", but is = " + tcount);
}

assertMaskReductionArraysEquals(r, a, Byte128VectorTests::maskTrueCount);
}

static int maskLastTrue(boolean[] a, int idx) {
int i = idx + SPECIES.length() - 1;
for (; i >= idx; i--) {
if (a[i]) {
break;
}
}
return i - idx;
}

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

for (int i = 0; i < a.length; i += SPECIES.length()) {
var vmask = SPECIES.loadMask(a, i);
int ltrue = vmask.lastTrue();
int j = i + SPECIES.length() - 1;
for (; j >= i; j--) {
if (a[j]) break;
for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
for (int i = 0; i < a.length; i += SPECIES.length()) {
var vmask = SPECIES.loadMask(a, i);
r[i] = vmask.lastTrue();
}
int expectedLtrue = j - i;
}

Assert.assertTrue(ltrue == expectedLtrue, "at index " + i +
", lastTrue should be = " + expectedLtrue + ", but is = " + ltrue);
assertMaskReductionArraysEquals(r, a, Byte128VectorTests::maskLastTrue);
}

static int maskFirstTrue(boolean[] a, int idx) {
int i = idx;
for (; i < idx + SPECIES.length(); i++) {
if (a[i]) {
break;
}
}
return i - idx;
}

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

for (int i = 0; i < a.length; i += SPECIES.length()) {
var vmask = SPECIES.loadMask(a, i);
int ftrue = vmask.firstTrue();
int j = i;
for (; j < i + SPECIES.length() ; j++) {
if (a[j]) break;
for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
for (int i = 0; i < a.length; i += SPECIES.length()) {
var vmask = SPECIES.loadMask(a, i);
r[i] = vmask.firstTrue();
}
int expectedFtrue = j - i;

Assert.assertTrue(ftrue == expectedFtrue, "at index " + i +
", firstTrue should be = " + expectedFtrue + ", but is = " + ftrue);
}

assertMaskReductionArraysEquals(r, a, Byte128VectorTests::maskFirstTrue);
}

@DataProvider
Expand Down
89 changes: 63 additions & 26 deletions test/jdk/jdk/incubator/vector/Byte256VectorTests.java
Expand Up @@ -211,6 +211,21 @@ static void assertReductionBoolArraysEquals(boolean[] r, boolean[] a, FBoolReduc
}
}

interface FMaskReductionOp {
int apply(boolean[] a, int idx);
}

static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReductionOp f) {
int i = 0;
try {
for (; i < a.length; i += SPECIES.length()) {
Assert.assertEquals(r[i], f.apply(a, i));
}
} catch (AssertionError e) {
Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i);
}
}

static void assertInsertArraysEquals(byte[] r, byte[] a, byte element, int index) {
int i = 0;
try {
Expand Down Expand Up @@ -5230,55 +5245,77 @@ static void maskHashCodeByte256VectorTestsSmokeTest(IntFunction<boolean[]> fa) {
}
}

static int maskTrueCount(boolean[] a, int idx) {
int trueCount = 0;
for (int i = idx; i < idx + SPECIES.length(); i++) {
trueCount += a[i] ? 1 : 0;
}
return trueCount;
}

@Test(dataProvider = "maskProvider")
static void maskTrueCountByte256VectorTestsSmokeTest(IntFunction<boolean[]> fa) {
boolean[] a = fa.apply(SPECIES.length());
int[] r = new int[a.length];

for (int i = 0; i < a.length; i += SPECIES.length()) {
var vmask = SPECIES.loadMask(a, i);
int tcount = vmask.trueCount();
int expectedTcount = 0;
for (int j = i; j < i + SPECIES.length(); j++) {
expectedTcount += a[j] ? 1 : 0;
for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
for (int i = 0; i < a.length; i += SPECIES.length()) {
var vmask = SPECIES.loadMask(a, i);
r[i] = vmask.trueCount();
}
Assert.assertTrue(tcount == expectedTcount, "at index " + i + ", trueCount should be = " + expectedTcount + ", but is = " + tcount);
}

assertMaskReductionArraysEquals(r, a, Byte256VectorTests::maskTrueCount);
}

static int maskLastTrue(boolean[] a, int idx) {
int i = idx + SPECIES.length() - 1;
for (; i >= idx; i--) {
if (a[i]) {
break;
}
}
return i - idx;
}

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

for (int i = 0; i < a.length; i += SPECIES.length()) {
var vmask = SPECIES.loadMask(a, i);
int ltrue = vmask.lastTrue();
int j = i + SPECIES.length() - 1;
for (; j >= i; j--) {
if (a[j]) break;
for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
for (int i = 0; i < a.length; i += SPECIES.length()) {
var vmask = SPECIES.loadMask(a, i);
r[i] = vmask.lastTrue();
}
int expectedLtrue = j - i;
}

Assert.assertTrue(ltrue == expectedLtrue, "at index " + i +
", lastTrue should be = " + expectedLtrue + ", but is = " + ltrue);
assertMaskReductionArraysEquals(r, a, Byte256VectorTests::maskLastTrue);
}

static int maskFirstTrue(boolean[] a, int idx) {
int i = idx;
for (; i < idx + SPECIES.length(); i++) {
if (a[i]) {
break;
}
}
return i - idx;
}

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

for (int i = 0; i < a.length; i += SPECIES.length()) {
var vmask = SPECIES.loadMask(a, i);
int ftrue = vmask.firstTrue();
int j = i;
for (; j < i + SPECIES.length() ; j++) {
if (a[j]) break;
for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
for (int i = 0; i < a.length; i += SPECIES.length()) {
var vmask = SPECIES.loadMask(a, i);
r[i] = vmask.firstTrue();
}
int expectedFtrue = j - i;

Assert.assertTrue(ftrue == expectedFtrue, "at index " + i +
", firstTrue should be = " + expectedFtrue + ", but is = " + ftrue);
}

assertMaskReductionArraysEquals(r, a, Byte256VectorTests::maskFirstTrue);
}

@DataProvider
Expand Down
89 changes: 63 additions & 26 deletions test/jdk/jdk/incubator/vector/Byte512VectorTests.java
Expand Up @@ -211,6 +211,21 @@ static void assertReductionBoolArraysEquals(boolean[] r, boolean[] a, FBoolReduc
}
}

interface FMaskReductionOp {
int apply(boolean[] a, int idx);
}

static void assertMaskReductionArraysEquals(int[] r, boolean[] a, FMaskReductionOp f) {
int i = 0;
try {
for (; i < a.length; i += SPECIES.length()) {
Assert.assertEquals(r[i], f.apply(a, i));
}
} catch (AssertionError e) {
Assert.assertEquals(r[i], f.apply(a, i), "at index #" + i);
}
}

static void assertInsertArraysEquals(byte[] r, byte[] a, byte element, int index) {
int i = 0;
try {
Expand Down Expand Up @@ -5230,55 +5245,77 @@ static void maskHashCodeByte512VectorTestsSmokeTest(IntFunction<boolean[]> fa) {
}
}

static int maskTrueCount(boolean[] a, int idx) {
int trueCount = 0;
for (int i = idx; i < idx + SPECIES.length(); i++) {
trueCount += a[i] ? 1 : 0;
}
return trueCount;
}

@Test(dataProvider = "maskProvider")
static void maskTrueCountByte512VectorTestsSmokeTest(IntFunction<boolean[]> fa) {
boolean[] a = fa.apply(SPECIES.length());
int[] r = new int[a.length];

for (int i = 0; i < a.length; i += SPECIES.length()) {
var vmask = SPECIES.loadMask(a, i);
int tcount = vmask.trueCount();
int expectedTcount = 0;
for (int j = i; j < i + SPECIES.length(); j++) {
expectedTcount += a[j] ? 1 : 0;
for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
for (int i = 0; i < a.length; i += SPECIES.length()) {
var vmask = SPECIES.loadMask(a, i);
r[i] = vmask.trueCount();
}
Assert.assertTrue(tcount == expectedTcount, "at index " + i + ", trueCount should be = " + expectedTcount + ", but is = " + tcount);
}

assertMaskReductionArraysEquals(r, a, Byte512VectorTests::maskTrueCount);
}

static int maskLastTrue(boolean[] a, int idx) {
int i = idx + SPECIES.length() - 1;
for (; i >= idx; i--) {
if (a[i]) {
break;
}
}
return i - idx;
}

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

for (int i = 0; i < a.length; i += SPECIES.length()) {
var vmask = SPECIES.loadMask(a, i);
int ltrue = vmask.lastTrue();
int j = i + SPECIES.length() - 1;
for (; j >= i; j--) {
if (a[j]) break;
for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
for (int i = 0; i < a.length; i += SPECIES.length()) {
var vmask = SPECIES.loadMask(a, i);
r[i] = vmask.lastTrue();
}
int expectedLtrue = j - i;
}

Assert.assertTrue(ltrue == expectedLtrue, "at index " + i +
", lastTrue should be = " + expectedLtrue + ", but is = " + ltrue);
assertMaskReductionArraysEquals(r, a, Byte512VectorTests::maskLastTrue);
}

static int maskFirstTrue(boolean[] a, int idx) {
int i = idx;
for (; i < idx + SPECIES.length(); i++) {
if (a[i]) {
break;
}
}
return i - idx;
}

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

for (int i = 0; i < a.length; i += SPECIES.length()) {
var vmask = SPECIES.loadMask(a, i);
int ftrue = vmask.firstTrue();
int j = i;
for (; j < i + SPECIES.length() ; j++) {
if (a[j]) break;
for (int ic = 0; ic < INVOC_COUNT * INVOC_COUNT; ic++) {
for (int i = 0; i < a.length; i += SPECIES.length()) {
var vmask = SPECIES.loadMask(a, i);
r[i] = vmask.firstTrue();
}
int expectedFtrue = j - i;

Assert.assertTrue(ftrue == expectedFtrue, "at index " + i +
", firstTrue should be = " + expectedFtrue + ", but is = " + ftrue);
}

assertMaskReductionArraysEquals(r, a, Byte512VectorTests::maskFirstTrue);
}

@DataProvider
Expand Down

1 comment on commit 2b20778

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.