Skip to content

Commit 10a049e

Browse files
Wang HuangAi Jiaming
authored andcommitted
8265956: JVM crashes when matching LShiftVB Node
Co-authored-by: Wang Huang <whuang@openjdk.org> Co-authored-by: Ai Jiaming <aijiaming1@huawei.com> Reviewed-by: kvn, jiefu
1 parent 9713152 commit 10a049e

File tree

2 files changed

+122
-2
lines changed

2 files changed

+122
-2
lines changed

src/hotspot/share/opto/vectorIntrinsics.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -369,7 +369,8 @@ bool LibraryCallKit::inline_vector_shuffle_iota() {
369369
res = gvn().transform(VectorNode::make(Op_MulI, res, bcast_step, num_elem, elem_bt));
370370
} else if (step_val->get_con() > 1) {
371371
Node* cnt = gvn().makecon(TypeInt::make(log2i_exact(step_val->get_con())));
372-
res = gvn().transform(VectorNode::make(Op_LShiftVB, res, cnt, vt));
372+
Node* shift_cnt = vector_shift_count(cnt, Op_LShiftI, elem_bt, num_elem);
373+
res = gvn().transform(VectorNode::make(Op_LShiftVB, res, shift_cnt, vt));
373374
}
374375

375376
if (!start_val->is_con() || start_val->get_con() != 0) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/*
2+
* Copyright (c) 2021, Huawei Technologies Co. Ltd. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
package compiler.vectorapi;
25+
26+
import jdk.incubator.vector.ByteVector;
27+
import jdk.incubator.vector.VectorSpecies;
28+
import jdk.incubator.vector.VectorShuffle;
29+
30+
import org.testng.Assert;
31+
import org.testng.annotations.Test;
32+
33+
34+
/*
35+
* @test
36+
* @bug 8265956
37+
* @modules jdk.incubator.vector
38+
* @run testng/othervm compiler.vectorapi.TestVectorShuffleIotaByte
39+
*/
40+
41+
@Test
42+
public class TestVectorShuffleIotaByte {
43+
static final VectorSpecies<Byte> SPECIESb_64 = ByteVector.SPECIES_64;
44+
static final VectorSpecies<Byte> SPECIESb_128 = ByteVector.SPECIES_128;
45+
static final VectorSpecies<Byte> SPECIESb_256 = ByteVector.SPECIES_256;
46+
static final VectorSpecies<Byte> SPECIESb_512 = ByteVector.SPECIES_512;
47+
48+
static final int INVOC_COUNT = Integer.getInteger("jdk.incubator.vector.test.loop-iterations", 50000);
49+
50+
static final byte[] ab_64 = {41, 45, 59, 46, 115, 101, 103, 97};
51+
static final byte[] ab_128 = {112, 32, 116, 117, 111, 104, 116, 105, 119, 32, 107, 111, 111, 98, 32, 97};
52+
static final byte[] ab_256 = {32, 101, 107, 105, 108, 32, 115, 105, 32, 117, 111, 121, 32, 116, 117, 111,
53+
104, 116, 105, 119, 32, 121, 97, 100, 32, 121, 114, 101, 118, 69, 32, 46};
54+
static final byte[] ab_512 = {103, 110, 97, 117, 72, 32, 71, 78, 65, 87, 32, 45, 45, 33, 117, 111, 121, 32,
55+
103, 110, 105, 115, 115, 105, 77, 32, 46, 117, 111, 121, 32, 111, 116, 32, 114,
56+
101, 116, 116, 101, 108, 32, 100, 114, 105, 104, 116, 32, 121, 109, 32, 115, 105,
57+
32, 115, 105, 104, 116, 44, 121, 116, 101, 101, 119, 83};
58+
59+
static final byte[] expected_64 = {1, 3, 5, 7, -7, -5, -3, -1};
60+
static final byte[] expected_128 = {1, 3, 5, 7, 9, 11, 13, 15, -15, -13, -11, -9, -7, -5, -3, -1};
61+
static final byte[] expected_256 = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31,
62+
-31, -29, -27, -25, -23, -21, -19, -17, -15, -13, -11, -9, -7, -5, -3, -1};
63+
static final byte[] expected_512 = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31,
64+
33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63,
65+
-63, -61, -59, -57, -55, -53, -51, -49, -47, -45, -43, -41, -39, -37, -35, -33,
66+
-31, -29, -27, -25, -23, -21, -19, -17, -15, -13, -11, -9, -7, -5, -3, -1};
67+
68+
static void testShuffleIota_64() {
69+
ByteVector bv1 = (ByteVector) VectorShuffle.iota(SPECIESb_64, 1, 2, false).toVector();
70+
bv1.intoArray(ab_64, 0);
71+
}
72+
73+
static void testShuffleIota_128() {
74+
ByteVector bv2 = (ByteVector) VectorShuffle.iota(SPECIESb_128, 1, 2, false).toVector();
75+
bv2.intoArray(ab_128, 0);
76+
}
77+
78+
static void testShuffleIota_256() {
79+
ByteVector bv3 = (ByteVector) VectorShuffle.iota(SPECIESb_256, 1, 2, false).toVector();
80+
bv3.intoArray(ab_256, 0);
81+
}
82+
83+
static void testShuffleIota_512() {
84+
ByteVector bv4 = (ByteVector) VectorShuffle.iota(SPECIESb_512, 1, 2, false).toVector();
85+
bv4.intoArray(ab_512, 0);
86+
}
87+
88+
@Test
89+
static void testIota_64() {
90+
for (int ic = 0; ic < INVOC_COUNT; ic++) {
91+
testShuffleIota_64();
92+
}
93+
Assert.assertEquals(ab_64, expected_64);
94+
}
95+
96+
@Test
97+
static void testIota_128() {
98+
for (int ic = 0; ic < INVOC_COUNT; ic++) {
99+
testShuffleIota_128();
100+
}
101+
Assert.assertEquals(ab_128, expected_128);
102+
}
103+
104+
@Test
105+
static void testIota_256() {
106+
for (int ic = 0; ic < INVOC_COUNT; ic++) {
107+
testShuffleIota_256();
108+
}
109+
Assert.assertEquals(ab_256, expected_256);
110+
}
111+
112+
@Test
113+
static void testIota_512() {
114+
for (int ic = 0; ic < INVOC_COUNT; ic++) {
115+
testShuffleIota_512();
116+
}
117+
Assert.assertEquals(ab_512, expected_512);
118+
}
119+
}

0 commit comments

Comments
 (0)