Skip to content

Commit 107ee87

Browse files
xyyNicoleJatin Bhateja
andcommitted
8346954: [JMH] jdk.incubator.vector.MaskedLogicOpts fails due to IndexOutOfBoundsException
Co-authored-by: Jatin Bhateja <jbhateja@openjdk.org> Reviewed-by: jbhateja, xgong
1 parent 11a37c8 commit 107ee87

File tree

1 file changed

+116
-140
lines changed

1 file changed

+116
-140
lines changed
Lines changed: 116 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2022, 2025, 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
@@ -37,19 +37,9 @@ public class MaskedLogicOpts {
3737
@Param({"256","512","1024"})
3838
private int ARRAYLEN;
3939

40-
boolean [] mask_arr = {
41-
false, false, false, true, false, false, false, false,
42-
false, false, false, true, false, false, false, false,
43-
false, false, false, true, false, false, false, false,
44-
true, true, true, true, true, true, true, true,
45-
true, true, true, true, true, true, true, true,
46-
false, false, false, true, false, false, false, false,
47-
false, false, false, true, false, false, false, false,
48-
false, false, false, true, false, false, false, false
49-
};
50-
5140
int INVOC_COUNTER = 4096;
5241

42+
boolean [] mask_arr = new boolean[ARRAYLEN];
5343
int [] i1 = new int[ARRAYLEN];
5444
int [] i2 = new int[ARRAYLEN];
5545
int [] i3 = new int[ARRAYLEN];
@@ -62,39 +52,23 @@ public class MaskedLogicOpts {
6252
long [] l4 = new long[ARRAYLEN];
6353
long [] l5 = new long[ARRAYLEN];
6454

65-
Vector<Integer> iv1;
66-
Vector<Integer> iv2;
67-
Vector<Integer> iv3;
68-
Vector<Integer> iv4;
69-
Vector<Integer> iv5;
70-
71-
Vector<Long> lv1;
72-
Vector<Long> lv2;
73-
Vector<Long> lv3;
74-
Vector<Long> lv4;
75-
Vector<Long> lv5;
76-
77-
VectorMask<Integer> imask;
78-
VectorMask<Long> lmask;
79-
80-
VectorSpecies<Integer> ispecies;
81-
VectorSpecies<Long> lspecies;
82-
8355
int int512_arr_idx;
8456
int int256_arr_idx;
8557
int int128_arr_idx;
8658
int long256_arr_idx;
8759
int long512_arr_idx;
8860

89-
private Random r = new Random();
61+
private Random r = new Random(1024);
9062

9163
@Setup(Level.Trial)
9264
public void init() {
93-
int512_arr_idx = 0;
94-
int256_arr_idx = 0;
95-
int128_arr_idx = 0;
96-
long256_arr_idx = 0;
97-
long512_arr_idx = 0;
65+
int512_arr_idx = -16;
66+
int256_arr_idx = -8;
67+
int128_arr_idx = -4;
68+
long256_arr_idx = -4;
69+
long512_arr_idx = -8;
70+
71+
mask_arr = new boolean[ARRAYLEN];
9872
i1 = new int[ARRAYLEN];
9973
i2 = new int[ARRAYLEN];
10074
i3 = new int[ARRAYLEN];
@@ -108,6 +82,8 @@ public void init() {
10882
l5 = new long[ARRAYLEN];
10983

11084
for (int i=0; i<ARRAYLEN; i++) {
85+
mask_arr[i] = r.nextBoolean();
86+
11187
i1[i] = r.nextInt();
11288
i2[i] = r.nextInt();
11389
i3[i] = r.nextInt();
@@ -125,22 +101,22 @@ public void init() {
125101

126102
@Setup(Level.Invocation)
127103
public void init_per_invoc() {
128-
int512_arr_idx = (int512_arr_idx + 16) & (ARRAYLEN-1);
129-
int256_arr_idx = (int256_arr_idx + 8) & (ARRAYLEN-1);
130-
int128_arr_idx = (int128_arr_idx + 4) & (ARRAYLEN-1);
131-
long512_arr_idx = (long512_arr_idx + 8) & (ARRAYLEN-1);
132-
long256_arr_idx = (long256_arr_idx + 4) & (ARRAYLEN-1);
104+
int512_arr_idx = (((ARRAYLEN & ~15) - int512_arr_idx) <= 16) ? 0 : int512_arr_idx + 16;
105+
int256_arr_idx = (((ARRAYLEN & ~7) - int256_arr_idx) <= 8) ? 0 : int256_arr_idx + 8;
106+
int128_arr_idx = (((ARRAYLEN & ~3) - int128_arr_idx) <= 4) ? 0 : int128_arr_idx + 4;
107+
long512_arr_idx = (((ARRAYLEN & ~7) - long512_arr_idx) <= 8) ? 0 : long512_arr_idx + 8;
108+
long256_arr_idx = (((ARRAYLEN & ~3) - long256_arr_idx) <= 4) ? 0 : long256_arr_idx + 4;
133109
}
134110

135111
@CompilerControl(CompilerControl.Mode.INLINE)
136-
public void maskedLogicKernel(VectorSpecies<Integer> SPECIES) {
137-
imask = VectorMask.fromArray(SPECIES, mask_arr, 0);
138-
iv2 = IntVector.fromArray(SPECIES, i2, int512_arr_idx);
139-
iv3 = IntVector.fromArray(SPECIES, i3, int512_arr_idx);
140-
iv4 = IntVector.fromArray(SPECIES, i4, int512_arr_idx);
141-
iv5 = IntVector.fromArray(SPECIES, i5, int512_arr_idx);
112+
public void maskedLogicKernel(VectorSpecies<Integer> SPECIES, int index) {
113+
VectorMask<Integer> imask = VectorMask.fromArray(SPECIES, mask_arr, index);
114+
IntVector iv2 = IntVector.fromArray(SPECIES, i2, index);
115+
IntVector iv3 = IntVector.fromArray(SPECIES, i3, index);
116+
IntVector iv4 = IntVector.fromArray(SPECIES, i4, index);
117+
IntVector iv5 = IntVector.fromArray(SPECIES, i5, index);
142118
for(int i = 0; i < INVOC_COUNTER; i++) {
143-
for(int j = 0 ; j < ARRAYLEN; j+= SPECIES.length()) {
119+
for(int j = 0 ; j < SPECIES.loopBound(ARRAYLEN); j+= SPECIES.length()) {
144120
IntVector.fromArray(SPECIES, i1, j)
145121
.lanewise(VectorOperators.AND, iv2, imask)
146122
.lanewise(VectorOperators.OR, iv2, imask)
@@ -157,65 +133,65 @@ public void maskedLogicKernel(VectorSpecies<Integer> SPECIES) {
157133

158134
@Benchmark
159135
public void maskedLogicOperationsInt512() {
160-
maskedLogicKernel(IntVector.SPECIES_512);
136+
maskedLogicKernel(IntVector.SPECIES_512, int512_arr_idx);
161137
}
162138

163139
@Benchmark
164140
public void maskedLogicOperationsInt256() {
165-
maskedLogicKernel(IntVector.SPECIES_256);
141+
maskedLogicKernel(IntVector.SPECIES_256, int256_arr_idx);
166142
}
167143

168144
@Benchmark
169145
public void maskedLogicOperationsInt128() {
170-
maskedLogicKernel(IntVector.SPECIES_128);
146+
maskedLogicKernel(IntVector.SPECIES_128, int128_arr_idx);
171147
}
172148

173149
@CompilerControl(CompilerControl.Mode.INLINE)
174-
public void partiallyMaskedLogicOperationsIntKernel(VectorSpecies<Integer> SPECIES) {
175-
imask = VectorMask.fromArray(SPECIES, mask_arr, 0);
176-
iv2 = IntVector.fromArray(SPECIES, i2, int512_arr_idx);
177-
iv3 = IntVector.fromArray(SPECIES, i3, int512_arr_idx);
178-
iv4 = IntVector.fromArray(SPECIES, i4, int512_arr_idx);
179-
iv5 = IntVector.fromArray(SPECIES, i5, int512_arr_idx);
180-
for(int i = 0; i < INVOC_COUNTER; i++) {
181-
for(int j = 0 ; j < ARRAYLEN; j+= SPECIES.length()) {
182-
IntVector.fromArray(SPECIES, i1, j)
183-
.lanewise(VectorOperators.AND, iv2, imask)
184-
.lanewise(VectorOperators.OR, iv2, imask)
185-
.lanewise(VectorOperators.AND, iv3)
186-
.lanewise(VectorOperators.OR, iv3)
187-
.lanewise(VectorOperators.OR, iv4, imask)
188-
.lanewise(VectorOperators.AND, iv4, imask)
189-
.lanewise(VectorOperators.XOR, iv5, imask)
190-
.intoArray(i1, j);
191-
}
192-
}
150+
public void partiallyMaskedLogicOperationsIntKernel(VectorSpecies<Integer> SPECIES, int index) {
151+
VectorMask<Integer> imask = VectorMask.fromArray(SPECIES, mask_arr, index);
152+
IntVector iv2 = IntVector.fromArray(SPECIES, i2, index);
153+
IntVector iv3 = IntVector.fromArray(SPECIES, i3, index);
154+
IntVector iv4 = IntVector.fromArray(SPECIES, i4, index);
155+
IntVector iv5 = IntVector.fromArray(SPECIES, i5, index);
156+
for (int i = 0; i < INVOC_COUNTER; i++) {
157+
for (int j = 0 ; j < SPECIES.loopBound(ARRAYLEN); j+= SPECIES.length()) {
158+
IntVector.fromArray(SPECIES, i1, j)
159+
.lanewise(VectorOperators.AND, iv2, imask)
160+
.lanewise(VectorOperators.OR, iv2, imask)
161+
.lanewise(VectorOperators.AND, iv3)
162+
.lanewise(VectorOperators.OR, iv3)
163+
.lanewise(VectorOperators.OR, iv4, imask)
164+
.lanewise(VectorOperators.AND, iv4, imask)
165+
.lanewise(VectorOperators.XOR, iv5, imask)
166+
.intoArray(i1, j);
167+
}
168+
}
193169
}
194170

195171
@Benchmark
196172
public void partiallyMaskedLogicOperationsInt512() {
197-
partiallyMaskedLogicOperationsIntKernel(IntVector.SPECIES_512);
173+
partiallyMaskedLogicOperationsIntKernel(IntVector.SPECIES_512, int512_arr_idx);
198174
}
199175

200176
@Benchmark
201177
public void partiallyMaskedLogicOperationsInt256() {
202-
partiallyMaskedLogicOperationsIntKernel(IntVector.SPECIES_256);
178+
partiallyMaskedLogicOperationsIntKernel(IntVector.SPECIES_256, int256_arr_idx);
203179
}
204180

205181
@Benchmark
206182
public void partiallyMaskedLogicOperationsInt128() {
207-
partiallyMaskedLogicOperationsIntKernel(IntVector.SPECIES_128);
183+
partiallyMaskedLogicOperationsIntKernel(IntVector.SPECIES_128, int128_arr_idx);
208184
}
209185

210186
@CompilerControl(CompilerControl.Mode.INLINE)
211-
public void bitwiseBlendOperationIntKernel(VectorSpecies<Integer> SPECIES) {
212-
imask = VectorMask.fromArray(SPECIES, mask_arr, 0);
213-
iv2 = IntVector.fromArray(SPECIES, i2, int512_arr_idx);
214-
iv3 = IntVector.fromArray(SPECIES, i3, int512_arr_idx);
215-
iv4 = IntVector.fromArray(SPECIES, i4, int512_arr_idx);
216-
iv5 = IntVector.fromArray(SPECIES, i5, int512_arr_idx);
217-
for(int i = 0; i < INVOC_COUNTER; i++) {
218-
for(int j = 0 ; j < ARRAYLEN; j+= SPECIES.length()) {
187+
public void bitwiseBlendOperationIntKernel(VectorSpecies<Integer> SPECIES, int index) {
188+
VectorMask<Integer> imask = VectorMask.fromArray(SPECIES, mask_arr, index);
189+
IntVector iv2 = IntVector.fromArray(SPECIES, i2, index);
190+
IntVector iv3 = IntVector.fromArray(SPECIES, i3, index);
191+
IntVector iv4 = IntVector.fromArray(SPECIES, i4, index);
192+
IntVector iv5 = IntVector.fromArray(SPECIES, i5, index);
193+
for (int i = 0; i < INVOC_COUNTER; i++) {
194+
for (int j = 0 ; j < SPECIES.loopBound(ARRAYLEN); j+= SPECIES.length()) {
219195
IntVector.fromArray(SPECIES, i1, j)
220196
.lanewise(VectorOperators.BITWISE_BLEND, iv2, iv3, imask)
221197
.lanewise(VectorOperators.BITWISE_BLEND, iv3, iv4, imask)
@@ -227,106 +203,106 @@ public void bitwiseBlendOperationIntKernel(VectorSpecies<Integer> SPECIES) {
227203

228204
@Benchmark
229205
public void bitwiseBlendOperationInt512() {
230-
bitwiseBlendOperationIntKernel(IntVector.SPECIES_512);
206+
bitwiseBlendOperationIntKernel(IntVector.SPECIES_512, int512_arr_idx);
231207
}
232208

233209
@Benchmark
234210
public void bitwiseBlendOperationInt256() {
235-
bitwiseBlendOperationIntKernel(IntVector.SPECIES_256);
211+
bitwiseBlendOperationIntKernel(IntVector.SPECIES_256, int256_arr_idx);
236212
}
237213

238214
@Benchmark
239215
public void bitwiseBlendOperationInt128() {
240-
bitwiseBlendOperationIntKernel(IntVector.SPECIES_128);
216+
bitwiseBlendOperationIntKernel(IntVector.SPECIES_128, int128_arr_idx);
241217
}
242218

243219
@CompilerControl(CompilerControl.Mode.INLINE)
244-
public void maskedLogicOperationsLongKernel(VectorSpecies<Long> SPECIES) {
245-
lmask = VectorMask.fromArray(SPECIES, mask_arr, 0);
246-
lv2 = LongVector.fromArray(SPECIES, l2, long256_arr_idx);
247-
lv3 = LongVector.fromArray(SPECIES, l3, long256_arr_idx);
248-
lv4 = LongVector.fromArray(SPECIES, l4, long256_arr_idx);
249-
lv5 = LongVector.fromArray(SPECIES, l5, long256_arr_idx);
250-
for(int i = 0; i < INVOC_COUNTER; i++) {
251-
for(int j = 0 ; j < ARRAYLEN; j+= SPECIES.length()) {
252-
LongVector.fromArray(SPECIES, l1, j)
253-
.lanewise(VectorOperators.AND, lv2, lmask)
254-
.lanewise(VectorOperators.OR, lv3, lmask)
255-
.lanewise(VectorOperators.AND, lv3, lmask)
256-
.lanewise(VectorOperators.OR, lv4, lmask)
257-
.lanewise(VectorOperators.AND, lv4, lmask)
258-
.lanewise(VectorOperators.XOR, lv5, lmask)
259-
.intoArray(l1, j);
260-
}
261-
}
220+
public void maskedLogicOperationsLongKernel(VectorSpecies<Long> SPECIES, int index) {
221+
VectorMask<Long> lmask = VectorMask.fromArray(SPECIES, mask_arr, index);
222+
LongVector lv2 = LongVector.fromArray(SPECIES, l2, index);
223+
LongVector lv3 = LongVector.fromArray(SPECIES, l3, index);
224+
LongVector lv4 = LongVector.fromArray(SPECIES, l4, index);
225+
LongVector lv5 = LongVector.fromArray(SPECIES, l5, index);
226+
for (int i = 0; i < INVOC_COUNTER; i++) {
227+
for (int j = 0 ; j < SPECIES.loopBound(ARRAYLEN); j+= SPECIES.length()) {
228+
LongVector.fromArray(SPECIES, l1, j)
229+
.lanewise(VectorOperators.AND, lv2, lmask)
230+
.lanewise(VectorOperators.OR, lv3, lmask)
231+
.lanewise(VectorOperators.AND, lv3, lmask)
232+
.lanewise(VectorOperators.OR, lv4, lmask)
233+
.lanewise(VectorOperators.AND, lv4, lmask)
234+
.lanewise(VectorOperators.XOR, lv5, lmask)
235+
.intoArray(l1, j);
236+
}
237+
}
262238
}
263239

264240
@Benchmark
265241
public void maskedLogicOperationsLong512() {
266-
maskedLogicOperationsLongKernel(LongVector.SPECIES_512);
242+
maskedLogicOperationsLongKernel(LongVector.SPECIES_512, long512_arr_idx);
267243
}
268244
@Benchmark
269245
public void maskedLogicOperationsLong256() {
270-
maskedLogicOperationsLongKernel(LongVector.SPECIES_256);
246+
maskedLogicOperationsLongKernel(LongVector.SPECIES_256, long256_arr_idx);
271247
}
272248

273249
@CompilerControl(CompilerControl.Mode.INLINE)
274-
public void partiallyMaskedLogicOperationsLongKernel(VectorSpecies<Long> SPECIES) {
275-
lmask = VectorMask.fromArray(SPECIES, mask_arr, 0);
276-
lv2 = LongVector.fromArray(SPECIES, l2, long512_arr_idx);
277-
lv3 = LongVector.fromArray(SPECIES, l3, long512_arr_idx);
278-
lv4 = LongVector.fromArray(SPECIES, l4, long512_arr_idx);
279-
lv5 = LongVector.fromArray(SPECIES, l5, long512_arr_idx);
280-
for(int i = 0; i < INVOC_COUNTER; i++) {
281-
for(int j = 0 ; j < ARRAYLEN; j+= SPECIES.length()) {
282-
LongVector.fromArray(SPECIES, l1, j)
283-
.lanewise(VectorOperators.AND, lv2, lmask)
284-
.lanewise(VectorOperators.OR, lv2, lmask)
285-
.lanewise(VectorOperators.AND, lv3)
286-
.lanewise(VectorOperators.OR, lv3)
287-
.lanewise(VectorOperators.AND, lv4)
288-
.lanewise(VectorOperators.OR, lv4, lmask)
289-
.lanewise(VectorOperators.XOR, lv5, lmask)
290-
.intoArray(l1, j);
291-
}
292-
}
250+
public void partiallyMaskedLogicOperationsLongKernel(VectorSpecies<Long> SPECIES, int index) {
251+
VectorMask<Long> lmask = VectorMask.fromArray(SPECIES, mask_arr, index);
252+
LongVector lv2 = LongVector.fromArray(SPECIES, l2, index);
253+
LongVector lv3 = LongVector.fromArray(SPECIES, l3, index);
254+
LongVector lv4 = LongVector.fromArray(SPECIES, l4, index);
255+
LongVector lv5 = LongVector.fromArray(SPECIES, l5, index);
256+
for (int i = 0; i < INVOC_COUNTER; i++) {
257+
for (int j = 0 ; j < SPECIES.loopBound(ARRAYLEN); j+= SPECIES.length()) {
258+
LongVector.fromArray(SPECIES, l1, j)
259+
.lanewise(VectorOperators.AND, lv2, lmask)
260+
.lanewise(VectorOperators.OR, lv2, lmask)
261+
.lanewise(VectorOperators.AND, lv3)
262+
.lanewise(VectorOperators.OR, lv3)
263+
.lanewise(VectorOperators.AND, lv4)
264+
.lanewise(VectorOperators.OR, lv4, lmask)
265+
.lanewise(VectorOperators.XOR, lv5, lmask)
266+
.intoArray(l1, j);
267+
}
268+
}
293269
}
294270

295271
@Benchmark
296272
public void partiallyMaskedLogicOperationsLong512() {
297-
partiallyMaskedLogicOperationsLongKernel(LongVector.SPECIES_512);
273+
partiallyMaskedLogicOperationsLongKernel(LongVector.SPECIES_512, long512_arr_idx);
298274
}
299275

300276
@Benchmark
301277
public void partiallyMaskedLogicOperationsLong256() {
302-
partiallyMaskedLogicOperationsLongKernel(LongVector.SPECIES_256);
278+
partiallyMaskedLogicOperationsLongKernel(LongVector.SPECIES_256, long256_arr_idx);
303279
}
304280

305281
@CompilerControl(CompilerControl.Mode.INLINE)
306-
public void bitwiseBlendOperationLongKernel(VectorSpecies<Long> SPECIES) {
307-
lmask = VectorMask.fromArray(SPECIES, mask_arr, 0);
308-
lv2 = LongVector.fromArray(SPECIES, l2, long512_arr_idx);
309-
lv3 = LongVector.fromArray(SPECIES, l3, long512_arr_idx);
310-
lv4 = LongVector.fromArray(SPECIES, l4, long512_arr_idx);
311-
lv5 = LongVector.fromArray(SPECIES, l5, long512_arr_idx);
312-
for(int i = 0; i < INVOC_COUNTER; i++) {
313-
for(int j = 0 ; j < ARRAYLEN; j+= SPECIES.length()) {
314-
LongVector.fromArray(SPECIES, l1, j)
315-
.lanewise(VectorOperators.BITWISE_BLEND, lv2, lv3, lmask)
316-
.lanewise(VectorOperators.BITWISE_BLEND, lv3, lv4, lmask)
317-
.lanewise(VectorOperators.BITWISE_BLEND, lv4, lv5, lmask)
318-
.intoArray(l1, j);
282+
public void bitwiseBlendOperationLongKernel(VectorSpecies<Long> SPECIES, int index) {
283+
VectorMask<Long> lmask = VectorMask.fromArray(SPECIES, mask_arr, index);
284+
LongVector lv2 = LongVector.fromArray(SPECIES, l2, index);
285+
LongVector lv3 = LongVector.fromArray(SPECIES, l3, index);
286+
LongVector lv4 = LongVector.fromArray(SPECIES, l4, index);
287+
LongVector lv5 = LongVector.fromArray(SPECIES, l5, index);
288+
for (int i = 0; i < INVOC_COUNTER; i++) {
289+
for (int j = 0 ; j < SPECIES.loopBound(ARRAYLEN); j+= SPECIES.length()) {
290+
LongVector.fromArray(SPECIES, l1, j)
291+
.lanewise(VectorOperators.BITWISE_BLEND, lv2, lv3, lmask)
292+
.lanewise(VectorOperators.BITWISE_BLEND, lv3, lv4, lmask)
293+
.lanewise(VectorOperators.BITWISE_BLEND, lv4, lv5, lmask)
294+
.intoArray(l1, j);
319295
}
320296
}
321297
}
322298

323299
@Benchmark
324300
public void bitwiseBlendOperationLong512() {
325-
bitwiseBlendOperationLongKernel(LongVector.SPECIES_512);
301+
bitwiseBlendOperationLongKernel(LongVector.SPECIES_512, long512_arr_idx);
326302
}
327303

328304
@Benchmark
329305
public void bitwiseBlendOperationLong256() {
330-
bitwiseBlendOperationLongKernel(LongVector.SPECIES_256);
306+
bitwiseBlendOperationLongKernel(LongVector.SPECIES_256, long256_arr_idx);
331307
}
332308
}

0 commit comments

Comments
 (0)