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

Commit 0fdf9cd

Browse files
casparcwangStuart Monteith
authored andcommitted
8260473: [vector] ZGC: VectorReshape test produces incorrect results with ZGC enabled
Co-authored-by: Stuart Monteith <smonteith@openjdk.org> Co-authored-by: Wang Chao <casparcwang@tencent.com> Reviewed-by: vlivanov, neliasso
1 parent bc41bb1 commit 0fdf9cd

File tree

2 files changed

+174
-9
lines changed

2 files changed

+174
-9
lines changed

src/hotspot/share/opto/vector.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*/
2424

2525
#include "precompiled.hpp"
26+
#include "gc/shared/barrierSet.hpp"
2627
#include "opto/castnode.hpp"
2728
#include "opto/graphKit.hpp"
2829
#include "opto/phaseX.hpp"
@@ -412,15 +413,17 @@ void PhaseVector::expand_vunbox_node(VectorUnboxNode* vec_unbox) {
412413

413414
Node* mem = vec_unbox->mem();
414415
Node* ctrl = vec_unbox->in(0);
415-
Node* vec_field_ld = LoadNode::make(gvn,
416-
ctrl,
417-
mem,
418-
vec_adr,
419-
vec_adr->bottom_type()->is_ptr(),
420-
TypeOopPtr::make_from_klass(field->type()->as_klass()),
421-
T_OBJECT,
422-
MemNode::unordered);
423-
vec_field_ld = gvn.transform(vec_field_ld);
416+
Node* vec_field_ld;
417+
{
418+
DecoratorSet decorators = MO_UNORDERED | IN_HEAP;
419+
C2AccessValuePtr addr(vec_adr, vec_adr->bottom_type()->is_ptr());
420+
MergeMemNode* local_mem = MergeMemNode::make(mem);
421+
gvn.record_for_igvn(local_mem);
422+
BarrierSetC2* bs = BarrierSet::barrier_set()->barrier_set_c2();
423+
C2OptAccess access(gvn, ctrl, local_mem, decorators, T_OBJECT, obj, addr);
424+
const Type* type = TypeOopPtr::make_from_klass(field->type()->as_klass());
425+
vec_field_ld = bs->load_at(access, type);
426+
}
424427

425428
// For proper aliasing, attach concrete payload type.
426429
ciKlass* payload_klass = ciTypeArrayKlass::make(bt);
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
/*
2+
* Copyright (c) 2021, Oracle and/or its affiliates. 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+
import jdk.incubator.vector.*;
24+
import jdk.internal.vm.annotation.ForceInline;
25+
import org.testng.Assert;
26+
import org.testng.annotations.Test;
27+
import org.testng.annotations.DataProvider;
28+
29+
import java.lang.invoke.MethodHandles;
30+
import java.lang.invoke.VarHandle;
31+
import java.nio.ByteOrder;
32+
import java.util.Arrays;
33+
import java.util.List;
34+
import java.util.function.IntFunction;
35+
import java.util.function.IntUnaryOperator;
36+
import jdk.incubator.vector.VectorShape;
37+
import jdk.incubator.vector.VectorSpecies;
38+
import jdk.internal.vm.annotation.ForceInline;
39+
40+
/*
41+
* @test
42+
* @bug 8260473
43+
* @requires vm.gc.Z
44+
* @modules jdk.incubator.vector
45+
* @modules java.base/jdk.internal.vm.annotation
46+
* @run testng/othervm -XX:CompileCommand=compileonly,jdk/incubator/vector/ByteVector.fromByteBuffer
47+
* -XX:-TieredCompilation -XX:CICompilerCount=1 -XX:+UseZGC -Xbatch -Xmx256m VectorRebracket128Test
48+
*/
49+
50+
@Test
51+
public class VectorRebracket128Test {
52+
static final int INVOC_COUNT = Integer.getInteger("jtreg.compiler.vectorapi.vectorrebracket128test.loop-iterations", 1000);
53+
static final int NUM_ITER = 200 * INVOC_COUNT;
54+
55+
static final VectorSpecies<Integer> ispec128 = IntVector.SPECIES_128;
56+
static final VectorSpecies<Float> fspec128 = FloatVector.SPECIES_128;
57+
static final VectorSpecies<Long> lspec128 = LongVector.SPECIES_128;
58+
static final VectorSpecies<Double> dspec128 = DoubleVector.SPECIES_128;
59+
static final VectorSpecies<Byte> bspec128 = ByteVector.SPECIES_128;
60+
static final VectorSpecies<Short> sspec128 = ShortVector.SPECIES_128;
61+
62+
static <T> IntFunction<T> withToString(String s, IntFunction<T> f) {
63+
return new IntFunction<T>() {
64+
@Override
65+
public T apply(int v) {
66+
return f.apply(v);
67+
}
68+
69+
@Override
70+
public String toString() {
71+
return s;
72+
}
73+
};
74+
}
75+
76+
interface ToByteF {
77+
byte apply(int i);
78+
}
79+
80+
static byte[] fill_byte(int s , ToByteF f) {
81+
return fill_byte(new byte[s], f);
82+
}
83+
84+
static byte[] fill_byte(byte[] a, ToByteF f) {
85+
for (int i = 0; i < a.length; i++) {
86+
a[i] = f.apply(i);
87+
}
88+
return a;
89+
}
90+
91+
static final List<IntFunction<byte[]>> BYTE_GENERATORS = List.of(
92+
withToString("byte(i)", (int s) -> {
93+
return fill_byte(s, i -> (byte)(i+1));
94+
})
95+
);
96+
97+
@DataProvider
98+
public Object[][] byteUnaryOpProvider() {
99+
return BYTE_GENERATORS.stream().
100+
map(f -> new Object[]{f}).
101+
toArray(Object[][]::new);
102+
}
103+
104+
static
105+
void checkPartialResult(VectorSpecies<?> a, VectorSpecies<?> b,
106+
byte[] input, byte[] output, byte[] expected,
107+
int part, int origin) {
108+
if (Arrays.equals(expected, output)) {
109+
return;
110+
}
111+
int block;
112+
block = Math.min(a.vectorByteSize(), b.vectorByteSize());
113+
114+
System.out.println("input: "+Arrays.toString(input));
115+
System.out.println("Failing with "+a+"->"+b+
116+
" (reinterpret)"+
117+
", block=" + block +
118+
", part=" + part +
119+
", origin=" + origin);
120+
System.out.println("expect: "+Arrays.toString(expected));
121+
System.out.println("output: "+Arrays.toString(output));
122+
Assert.assertEquals(expected, output);
123+
}
124+
125+
@ForceInline
126+
static <E,F>
127+
void testVectorRebracket(VectorSpecies<E> a, VectorSpecies<F> b, byte[] input, byte[] output) {
128+
Vector<E> av = a.fromByteArray(input, 0, ByteOrder.nativeOrder());
129+
int block;
130+
assert(input.length == output.length);
131+
132+
block = Math.min(a.vectorByteSize(), b.vectorByteSize());
133+
if (false)
134+
System.out.println("testing "+a+"->"+b+
135+
(false?" (lanewise)":" (reinterpret)")+
136+
", block=" + block);
137+
byte[] expected;
138+
int origin;
139+
140+
int part = 0;
141+
Vector<F> bv = av.reinterpretShape(b, part);
142+
bv.intoByteArray(output, 0, ByteOrder.nativeOrder());
143+
// in-place copy, no resize
144+
expected = input;
145+
origin = 0;
146+
checkPartialResult(a, b, input, output, expected,
147+
part, origin);
148+
149+
}
150+
151+
@Test(dataProvider = "byteUnaryOpProvider")
152+
static void testRebracket128(IntFunction<byte[]> fa) {
153+
byte[] barr = fa.apply(128/Byte.SIZE);
154+
byte[] bout = new byte[barr.length];
155+
for (int i = 0; i < NUM_ITER; i++) {
156+
testVectorRebracket(bspec128, bspec128, barr, bout);
157+
testVectorRebracket(bspec128, sspec128, barr, bout);
158+
testVectorRebracket(bspec128, ispec128, barr, bout);
159+
}
160+
}
161+
162+
}

0 commit comments

Comments
 (0)