author | amurillo |
Tue, 17 May 2016 05:38:15 -0700 | |
changeset 38368 | c8eb5d6812c5 |
parent 38358 | cb99c6d2af1b |
parent 38328 | 40435a469d25 |
child 38382 | 98d5a441bc2f |
permissions | -rw-r--r-- |
36934 | 1 |
/* |
2 |
* Copyright (c) 2015, 2016, 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 |
||
24 |
/* |
|
25 |
* @test |
|
37668
34a002e5168a
8154556: Use java.nio.ByteOrder instead of boolean value
psandoz
parents:
37343
diff
changeset
|
26 |
* @bug 8154556 |
36934 | 27 |
* @run testng/othervm -Diters=20000 -XX:TieredStopAtLevel=1 VarHandleTestByteArrayAsFloat |
28 |
* @run testng/othervm -Diters=20000 VarHandleTestByteArrayAsFloat |
|
29 |
* @run testng/othervm -Diters=20000 -XX:-TieredCompilation VarHandleTestByteArrayAsFloat |
|
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37719
diff
changeset
|
30 |
* @run testng/othervm -Diters=20000 -Djava.lang.invoke.VarHandle.VAR_HANDLE_GUARDS=false VarHandleTestByteArrayAsFloat |
36934 | 31 |
*/ |
32 |
||
33 |
import org.testng.annotations.DataProvider; |
|
34 |
import org.testng.annotations.Test; |
|
35 |
||
36 |
import java.lang.invoke.MethodHandles; |
|
37 |
import java.lang.invoke.VarHandle; |
|
38 |
import java.nio.ByteBuffer; |
|
39 |
import java.nio.ByteOrder; |
|
40 |
import java.util.ArrayList; |
|
41 |
import java.util.Arrays; |
|
42 |
import java.util.EnumSet; |
|
43 |
import java.util.List; |
|
44 |
||
45 |
import static org.testng.Assert.*; |
|
46 |
||
47 |
public class VarHandleTestByteArrayAsFloat extends VarHandleBaseByteArrayTest { |
|
48 |
static final int SIZE = Float.BYTES; |
|
49 |
||
50 |
static final float VALUE_1 = 0x01020304; |
|
51 |
||
52 |
static final float VALUE_2 = 0x11121314; |
|
53 |
||
54 |
static final float VALUE_3 = 0x21222324; |
|
55 |
||
56 |
||
57 |
@Override |
|
58 |
public void setupVarHandleSources() { |
|
59 |
// Combinations of VarHandle byte[] or ByteBuffer |
|
60 |
vhss = new ArrayList<>(); |
|
61 |
for (MemoryMode endianess : Arrays.asList(MemoryMode.BIG_ENDIAN, MemoryMode.LITTLE_ENDIAN)) { |
|
37668
34a002e5168a
8154556: Use java.nio.ByteOrder instead of boolean value
psandoz
parents:
37343
diff
changeset
|
62 |
|
34a002e5168a
8154556: Use java.nio.ByteOrder instead of boolean value
psandoz
parents:
37343
diff
changeset
|
63 |
ByteOrder bo = endianess == MemoryMode.BIG_ENDIAN |
34a002e5168a
8154556: Use java.nio.ByteOrder instead of boolean value
psandoz
parents:
37343
diff
changeset
|
64 |
? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN; |
36934 | 65 |
VarHandleSource aeh = new VarHandleSource( |
37668
34a002e5168a
8154556: Use java.nio.ByteOrder instead of boolean value
psandoz
parents:
37343
diff
changeset
|
66 |
MethodHandles.byteArrayViewVarHandle(float[].class, bo), |
36934 | 67 |
endianess, MemoryMode.READ_WRITE); |
68 |
vhss.add(aeh); |
|
69 |
||
70 |
VarHandleSource bbh = new VarHandleSource( |
|
37668
34a002e5168a
8154556: Use java.nio.ByteOrder instead of boolean value
psandoz
parents:
37343
diff
changeset
|
71 |
MethodHandles.byteBufferViewVarHandle(float[].class, bo), |
36934 | 72 |
endianess, MemoryMode.READ_WRITE); |
73 |
vhss.add(bbh); |
|
74 |
} |
|
75 |
} |
|
76 |
||
77 |
||
78 |
@Test(dataProvider = "varHandlesProvider") |
|
79 |
public void testIsAccessModeSupported(VarHandleSource vhs) { |
|
80 |
VarHandle vh = vhs.s; |
|
81 |
||
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
82 |
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET)); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
83 |
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET)); |
36934 | 84 |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
85 |
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_VOLATILE)); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
86 |
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_VOLATILE)); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
87 |
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_ACQUIRE)); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
88 |
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_RELEASE)); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
89 |
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_OPAQUE)); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
90 |
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE)); |
36934 | 91 |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
92 |
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET)); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
93 |
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_VOLATILE)); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
94 |
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE)); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
95 |
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE)); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
96 |
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET)); |
37719
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37668
diff
changeset
|
97 |
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_VOLATILE)); |
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
98 |
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_ACQUIRE)); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
99 |
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.WEAK_COMPARE_AND_SET_RELEASE)); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
100 |
assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_SET)); |
36934 | 101 |
|
37343
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
102 |
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.GET_AND_ADD)); |
35a2231828a7
8151705: VarHandle.AccessMode enum names should conform to code style
psandoz
parents:
36934
diff
changeset
|
103 |
assertFalse(vh.isAccessModeSupported(VarHandle.AccessMode.ADD_AND_GET)); |
36934 | 104 |
} |
105 |
||
106 |
@Test(dataProvider = "typesProvider") |
|
107 |
public void testTypes(VarHandle vh, List<java.lang.Class<?>> pts) { |
|
108 |
assertEquals(vh.varType(), float.class); |
|
109 |
||
110 |
assertEquals(vh.coordinateTypes(), pts); |
|
111 |
||
112 |
testTypes(vh); |
|
113 |
} |
|
114 |
||
115 |
||
116 |
@DataProvider |
|
117 |
public Object[][] accessTestCaseProvider() throws Exception { |
|
118 |
List<AccessTestCase<?>> cases = new ArrayList<>(); |
|
119 |
||
120 |
for (ByteArrayViewSource<?> bav : bavss) { |
|
121 |
for (VarHandleSource vh : vhss) { |
|
122 |
if (vh.matches(bav)) { |
|
123 |
if (bav instanceof ByteArraySource) { |
|
124 |
ByteArraySource bas = (ByteArraySource) bav; |
|
125 |
||
126 |
cases.add(new VarHandleSourceAccessTestCase( |
|
127 |
"read write", bav, vh, h -> testArrayReadWrite(bas, h), |
|
128 |
true)); |
|
129 |
cases.add(new VarHandleSourceAccessTestCase( |
|
130 |
"unsupported", bav, vh, h -> testArrayUnsupported(bas, h), |
|
131 |
false)); |
|
132 |
cases.add(new VarHandleSourceAccessTestCase( |
|
133 |
"index out of bounds", bav, vh, h -> testArrayIndexOutOfBounds(bas, h), |
|
134 |
false)); |
|
135 |
cases.add(new VarHandleSourceAccessTestCase( |
|
136 |
"misaligned access", bav, vh, h -> testArrayMisalignedAccess(bas, h), |
|
137 |
false)); |
|
138 |
} |
|
139 |
else { |
|
140 |
ByteBufferSource bbs = (ByteBufferSource) bav; |
|
141 |
||
142 |
if (MemoryMode.READ_WRITE.isSet(bav.memoryModes)) { |
|
143 |
cases.add(new VarHandleSourceAccessTestCase( |
|
144 |
"read write", bav, vh, h -> testArrayReadWrite(bbs, h), |
|
145 |
true)); |
|
146 |
} |
|
147 |
else { |
|
148 |
cases.add(new VarHandleSourceAccessTestCase( |
|
149 |
"read only", bav, vh, h -> testArrayReadOnly(bbs, h), |
|
150 |
true)); |
|
151 |
} |
|
152 |
||
153 |
cases.add(new VarHandleSourceAccessTestCase( |
|
154 |
"unsupported", bav, vh, h -> testArrayUnsupported(bbs, h), |
|
155 |
false)); |
|
156 |
cases.add(new VarHandleSourceAccessTestCase( |
|
157 |
"index out of bounds", bav, vh, h -> testArrayIndexOutOfBounds(bbs, h), |
|
158 |
false)); |
|
159 |
cases.add(new VarHandleSourceAccessTestCase( |
|
160 |
"misaligned access", bav, vh, h -> testArrayMisalignedAccess(bbs, h), |
|
161 |
false)); |
|
162 |
} |
|
163 |
} |
|
164 |
} |
|
165 |
} |
|
166 |
||
167 |
// Work around issue with jtreg summary reporting which truncates |
|
168 |
// the String result of Object.toString to 30 characters, hence |
|
169 |
// the first dummy argument |
|
170 |
return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new); |
|
171 |
} |
|
172 |
||
173 |
@Test(dataProvider = "accessTestCaseProvider") |
|
174 |
public <T> void testAccess(String desc, AccessTestCase<T> atc) throws Throwable { |
|
175 |
T t = atc.get(); |
|
176 |
int iters = atc.requiresLoop() ? ITERS : 1; |
|
177 |
for (int c = 0; c < iters; c++) { |
|
178 |
atc.testAccess(t); |
|
179 |
} |
|
180 |
} |
|
181 |
||
182 |
||
183 |
static void testArrayUnsupported(ByteArraySource bs, VarHandleSource vhs) { |
|
184 |
VarHandle vh = vhs.s; |
|
185 |
byte[] array = bs.s; |
|
186 |
int ci = 1; |
|
187 |
||
188 |
||
189 |
checkUOE(() -> { |
|
190 |
float o = (float) vh.getAndAdd(array, ci, VALUE_1); |
|
191 |
}); |
|
192 |
||
193 |
checkUOE(() -> { |
|
194 |
float o = (float) vh.addAndGet(array, ci, VALUE_1); |
|
195 |
}); |
|
196 |
} |
|
197 |
||
198 |
static void testArrayUnsupported(ByteBufferSource bs, VarHandleSource vhs) { |
|
199 |
VarHandle vh = vhs.s; |
|
200 |
ByteBuffer array = bs.s; |
|
201 |
int ci = 0; |
|
202 |
boolean readOnly = MemoryMode.READ_ONLY.isSet(bs.memoryModes); |
|
203 |
||
204 |
if (readOnly) { |
|
205 |
checkROBE(() -> { |
|
206 |
vh.set(array, ci, VALUE_1); |
|
207 |
}); |
|
208 |
} |
|
209 |
||
210 |
if (readOnly) { |
|
211 |
checkROBE(() -> { |
|
212 |
vh.setVolatile(array, ci, VALUE_1); |
|
213 |
}); |
|
214 |
||
215 |
checkROBE(() -> { |
|
216 |
vh.setRelease(array, ci, VALUE_1); |
|
217 |
}); |
|
218 |
||
219 |
checkROBE(() -> { |
|
220 |
vh.setOpaque(array, ci, VALUE_1); |
|
221 |
}); |
|
222 |
||
223 |
checkROBE(() -> { |
|
224 |
boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2); |
|
225 |
}); |
|
226 |
||
227 |
checkROBE(() -> { |
|
228 |
float r = (float) vh.compareAndExchangeVolatile(array, ci, VALUE_2, VALUE_1); |
|
229 |
}); |
|
230 |
||
231 |
checkROBE(() -> { |
|
232 |
float r = (float) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1); |
|
233 |
}); |
|
234 |
||
235 |
checkROBE(() -> { |
|
236 |
float r = (float) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1); |
|
237 |
}); |
|
238 |
||
239 |
checkROBE(() -> { |
|
240 |
boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2); |
|
241 |
}); |
|
242 |
||
243 |
checkROBE(() -> { |
|
37719
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37668
diff
changeset
|
244 |
boolean r = vh.weakCompareAndSetVolatile(array, ci, VALUE_1, VALUE_2); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37668
diff
changeset
|
245 |
}); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37668
diff
changeset
|
246 |
|
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37668
diff
changeset
|
247 |
checkROBE(() -> { |
36934 | 248 |
boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2); |
249 |
}); |
|
250 |
||
251 |
checkROBE(() -> { |
|
252 |
boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2); |
|
253 |
}); |
|
254 |
||
255 |
checkROBE(() -> { |
|
256 |
float o = (float) vh.getAndSet(array, ci, VALUE_1); |
|
257 |
}); |
|
38328
40435a469d25
8156485: MethodHandles.varHandleExactInvoker should perform exact checks
psandoz
parents:
37719
diff
changeset
|
258 |
|
36934 | 259 |
|
260 |
checkUOE(() -> { |
|
261 |
float o = (float) vh.getAndAdd(array, ci, VALUE_1); |
|
262 |
}); |
|
263 |
||
264 |
checkUOE(() -> { |
|
265 |
float o = (float) vh.addAndGet(array, ci, VALUE_1); |
|
266 |
}); |
|
267 |
} |
|
268 |
else { |
|
269 |
checkUOE(() -> { |
|
270 |
float o = (float) vh.getAndAdd(array, ci, VALUE_1); |
|
271 |
}); |
|
272 |
||
273 |
checkUOE(() -> { |
|
274 |
float o = (float) vh.addAndGet(array, ci, VALUE_1); |
|
275 |
}); |
|
276 |
} |
|
277 |
} |
|
278 |
||
279 |
||
280 |
static void testArrayIndexOutOfBounds(ByteArraySource bs, VarHandleSource vhs) throws Throwable { |
|
281 |
VarHandle vh = vhs.s; |
|
282 |
byte[] array = bs.s; |
|
283 |
||
284 |
int length = array.length - SIZE + 1; |
|
285 |
for (int i : new int[]{-1, Integer.MIN_VALUE, length, length + 1, Integer.MAX_VALUE}) { |
|
286 |
final int ci = i; |
|
287 |
||
288 |
checkIOOBE(() -> { |
|
289 |
float x = (float) vh.get(array, ci); |
|
290 |
}); |
|
291 |
||
292 |
checkIOOBE(() -> { |
|
293 |
vh.set(array, ci, VALUE_1); |
|
294 |
}); |
|
295 |
||
296 |
checkIOOBE(() -> { |
|
297 |
float x = (float) vh.getVolatile(array, ci); |
|
298 |
}); |
|
299 |
||
300 |
checkIOOBE(() -> { |
|
301 |
float x = (float) vh.getAcquire(array, ci); |
|
302 |
}); |
|
303 |
||
304 |
checkIOOBE(() -> { |
|
305 |
float x = (float) vh.getOpaque(array, ci); |
|
306 |
}); |
|
307 |
||
308 |
checkIOOBE(() -> { |
|
309 |
vh.setVolatile(array, ci, VALUE_1); |
|
310 |
}); |
|
311 |
||
312 |
checkIOOBE(() -> { |
|
313 |
vh.setRelease(array, ci, VALUE_1); |
|
314 |
}); |
|
315 |
||
316 |
checkIOOBE(() -> { |
|
317 |
vh.setOpaque(array, ci, VALUE_1); |
|
318 |
}); |
|
319 |
||
320 |
checkIOOBE(() -> { |
|
321 |
boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2); |
|
322 |
}); |
|
323 |
||
324 |
checkIOOBE(() -> { |
|
325 |
float r = (float) vh.compareAndExchangeVolatile(array, ci, VALUE_2, VALUE_1); |
|
326 |
}); |
|
327 |
||
328 |
checkIOOBE(() -> { |
|
329 |
float r = (float) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1); |
|
330 |
}); |
|
331 |
||
332 |
checkIOOBE(() -> { |
|
333 |
float r = (float) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1); |
|
334 |
}); |
|
335 |
||
336 |
checkIOOBE(() -> { |
|
337 |
boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2); |
|
338 |
}); |
|
339 |
||
340 |
checkIOOBE(() -> { |
|
37719
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37668
diff
changeset
|
341 |
boolean r = vh.weakCompareAndSetVolatile(array, ci, VALUE_1, VALUE_2); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37668
diff
changeset
|
342 |
}); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37668
diff
changeset
|
343 |
|
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37668
diff
changeset
|
344 |
checkIOOBE(() -> { |
36934 | 345 |
boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2); |
346 |
}); |
|
347 |
||
348 |
checkIOOBE(() -> { |
|
349 |
boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2); |
|
350 |
}); |
|
351 |
||
352 |
checkIOOBE(() -> { |
|
353 |
float o = (float) vh.getAndSet(array, ci, VALUE_1); |
|
354 |
}); |
|
355 |
||
356 |
||
357 |
} |
|
358 |
} |
|
359 |
||
360 |
static void testArrayIndexOutOfBounds(ByteBufferSource bs, VarHandleSource vhs) throws Throwable { |
|
361 |
VarHandle vh = vhs.s; |
|
362 |
ByteBuffer array = bs.s; |
|
363 |
||
364 |
boolean readOnly = MemoryMode.READ_ONLY.isSet(bs.memoryModes); |
|
365 |
||
366 |
int length = array.limit() - SIZE + 1; |
|
367 |
for (int i : new int[]{-1, Integer.MIN_VALUE, length, length + 1, Integer.MAX_VALUE}) { |
|
368 |
final int ci = i; |
|
369 |
||
370 |
checkIOOBE(() -> { |
|
371 |
float x = (float) vh.get(array, ci); |
|
372 |
}); |
|
373 |
||
374 |
if (!readOnly) { |
|
375 |
checkIOOBE(() -> { |
|
376 |
vh.set(array, ci, VALUE_1); |
|
377 |
}); |
|
378 |
} |
|
379 |
||
380 |
checkIOOBE(() -> { |
|
381 |
float x = (float) vh.getVolatile(array, ci); |
|
382 |
}); |
|
383 |
||
384 |
checkIOOBE(() -> { |
|
385 |
float x = (float) vh.getAcquire(array, ci); |
|
386 |
}); |
|
387 |
||
388 |
checkIOOBE(() -> { |
|
389 |
float x = (float) vh.getOpaque(array, ci); |
|
390 |
}); |
|
391 |
||
392 |
if (!readOnly) { |
|
393 |
checkIOOBE(() -> { |
|
394 |
vh.setVolatile(array, ci, VALUE_1); |
|
395 |
}); |
|
396 |
||
397 |
checkIOOBE(() -> { |
|
398 |
vh.setRelease(array, ci, VALUE_1); |
|
399 |
}); |
|
400 |
||
401 |
checkIOOBE(() -> { |
|
402 |
vh.setOpaque(array, ci, VALUE_1); |
|
403 |
}); |
|
404 |
||
405 |
checkIOOBE(() -> { |
|
406 |
boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2); |
|
407 |
}); |
|
408 |
||
409 |
checkIOOBE(() -> { |
|
410 |
float r = (float) vh.compareAndExchangeVolatile(array, ci, VALUE_2, VALUE_1); |
|
411 |
}); |
|
412 |
||
413 |
checkIOOBE(() -> { |
|
414 |
float r = (float) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1); |
|
415 |
}); |
|
416 |
||
417 |
checkIOOBE(() -> { |
|
418 |
float r = (float) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1); |
|
419 |
}); |
|
420 |
||
421 |
checkIOOBE(() -> { |
|
422 |
boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2); |
|
423 |
}); |
|
424 |
||
425 |
checkIOOBE(() -> { |
|
37719
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37668
diff
changeset
|
426 |
boolean r = vh.weakCompareAndSetVolatile(array, ci, VALUE_1, VALUE_2); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37668
diff
changeset
|
427 |
}); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37668
diff
changeset
|
428 |
|
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37668
diff
changeset
|
429 |
checkIOOBE(() -> { |
36934 | 430 |
boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2); |
431 |
}); |
|
432 |
||
433 |
checkIOOBE(() -> { |
|
434 |
boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2); |
|
435 |
}); |
|
436 |
||
437 |
checkIOOBE(() -> { |
|
438 |
float o = (float) vh.getAndSet(array, ci, VALUE_1); |
|
439 |
}); |
|
440 |
||
441 |
} |
|
442 |
} |
|
443 |
} |
|
444 |
||
445 |
static void testArrayMisalignedAccess(ByteArraySource bs, VarHandleSource vhs) throws Throwable { |
|
446 |
VarHandle vh = vhs.s; |
|
447 |
byte[] array = bs.s; |
|
448 |
||
449 |
int misalignmentAtZero = ByteBuffer.wrap(array).alignmentOffset(0, SIZE); |
|
450 |
||
451 |
int length = array.length - SIZE + 1; |
|
452 |
for (int i = 0; i < length; i++) { |
|
453 |
boolean iAligned = ((i + misalignmentAtZero) & (SIZE - 1)) == 0; |
|
454 |
final int ci = i; |
|
455 |
||
456 |
if (!iAligned) { |
|
457 |
checkISE(() -> { |
|
458 |
float x = (float) vh.getVolatile(array, ci); |
|
459 |
}); |
|
460 |
||
461 |
checkISE(() -> { |
|
462 |
float x = (float) vh.getAcquire(array, ci); |
|
463 |
}); |
|
464 |
||
465 |
checkISE(() -> { |
|
466 |
float x = (float) vh.getOpaque(array, ci); |
|
467 |
}); |
|
468 |
||
469 |
checkISE(() -> { |
|
470 |
vh.setVolatile(array, ci, VALUE_1); |
|
471 |
}); |
|
472 |
||
473 |
checkISE(() -> { |
|
474 |
vh.setRelease(array, ci, VALUE_1); |
|
475 |
}); |
|
476 |
||
477 |
checkISE(() -> { |
|
478 |
vh.setOpaque(array, ci, VALUE_1); |
|
479 |
}); |
|
480 |
||
481 |
checkISE(() -> { |
|
482 |
boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2); |
|
483 |
}); |
|
484 |
||
485 |
checkISE(() -> { |
|
486 |
float r = (float) vh.compareAndExchangeVolatile(array, ci, VALUE_2, VALUE_1); |
|
487 |
}); |
|
488 |
||
489 |
checkISE(() -> { |
|
490 |
float r = (float) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1); |
|
491 |
}); |
|
492 |
||
493 |
checkISE(() -> { |
|
494 |
float r = (float) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1); |
|
495 |
}); |
|
496 |
||
497 |
checkISE(() -> { |
|
498 |
boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2); |
|
499 |
}); |
|
500 |
||
501 |
checkISE(() -> { |
|
37719
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37668
diff
changeset
|
502 |
boolean r = vh.weakCompareAndSetVolatile(array, ci, VALUE_1, VALUE_2); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37668
diff
changeset
|
503 |
}); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37668
diff
changeset
|
504 |
|
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37668
diff
changeset
|
505 |
checkISE(() -> { |
36934 | 506 |
boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2); |
507 |
}); |
|
508 |
||
509 |
checkISE(() -> { |
|
510 |
boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2); |
|
511 |
}); |
|
512 |
||
513 |
checkISE(() -> { |
|
514 |
float o = (float) vh.getAndSet(array, ci, VALUE_1); |
|
515 |
}); |
|
516 |
||
517 |
||
518 |
} |
|
519 |
} |
|
520 |
} |
|
521 |
||
522 |
static void testArrayMisalignedAccess(ByteBufferSource bs, VarHandleSource vhs) throws Throwable { |
|
523 |
VarHandle vh = vhs.s; |
|
524 |
ByteBuffer array = bs.s; |
|
525 |
||
526 |
boolean readOnly = MemoryMode.READ_ONLY.isSet(bs.memoryModes); |
|
527 |
int misalignmentAtZero = array.alignmentOffset(0, SIZE); |
|
528 |
||
529 |
int length = array.limit() - SIZE + 1; |
|
530 |
for (int i = 0; i < length; i++) { |
|
531 |
boolean iAligned = ((i + misalignmentAtZero) & (SIZE - 1)) == 0; |
|
532 |
final int ci = i; |
|
533 |
||
534 |
if (!iAligned) { |
|
535 |
checkISE(() -> { |
|
536 |
float x = (float) vh.getVolatile(array, ci); |
|
537 |
}); |
|
538 |
||
539 |
checkISE(() -> { |
|
540 |
float x = (float) vh.getAcquire(array, ci); |
|
541 |
}); |
|
542 |
||
543 |
checkISE(() -> { |
|
544 |
float x = (float) vh.getOpaque(array, ci); |
|
545 |
}); |
|
546 |
||
547 |
if (!readOnly) { |
|
548 |
checkISE(() -> { |
|
549 |
vh.setVolatile(array, ci, VALUE_1); |
|
550 |
}); |
|
551 |
||
552 |
checkISE(() -> { |
|
553 |
vh.setRelease(array, ci, VALUE_1); |
|
554 |
}); |
|
555 |
||
556 |
checkISE(() -> { |
|
557 |
vh.setOpaque(array, ci, VALUE_1); |
|
558 |
}); |
|
559 |
||
560 |
checkISE(() -> { |
|
561 |
boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2); |
|
562 |
}); |
|
563 |
||
564 |
checkISE(() -> { |
|
565 |
float r = (float) vh.compareAndExchangeVolatile(array, ci, VALUE_2, VALUE_1); |
|
566 |
}); |
|
567 |
||
568 |
checkISE(() -> { |
|
569 |
float r = (float) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1); |
|
570 |
}); |
|
571 |
||
572 |
checkISE(() -> { |
|
573 |
float r = (float) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1); |
|
574 |
}); |
|
575 |
||
576 |
checkISE(() -> { |
|
577 |
boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2); |
|
578 |
}); |
|
579 |
||
580 |
checkISE(() -> { |
|
37719
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37668
diff
changeset
|
581 |
boolean r = vh.weakCompareAndSetVolatile(array, ci, VALUE_1, VALUE_2); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37668
diff
changeset
|
582 |
}); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37668
diff
changeset
|
583 |
|
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37668
diff
changeset
|
584 |
checkISE(() -> { |
36934 | 585 |
boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2); |
586 |
}); |
|
587 |
||
588 |
checkISE(() -> { |
|
589 |
boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2); |
|
590 |
}); |
|
591 |
||
592 |
checkISE(() -> { |
|
593 |
float o = (float) vh.getAndSet(array, ci, VALUE_1); |
|
594 |
}); |
|
595 |
||
596 |
} |
|
597 |
} |
|
598 |
} |
|
599 |
} |
|
600 |
||
601 |
static void testArrayReadWrite(ByteArraySource bs, VarHandleSource vhs) { |
|
602 |
VarHandle vh = vhs.s; |
|
603 |
byte[] array = bs.s; |
|
604 |
||
605 |
int misalignmentAtZero = ByteBuffer.wrap(array).alignmentOffset(0, SIZE); |
|
606 |
||
607 |
bs.fill((byte) 0xff); |
|
608 |
int length = array.length - SIZE + 1; |
|
609 |
for (int i = 0; i < length; i++) { |
|
610 |
boolean iAligned = ((i + misalignmentAtZero) & (SIZE - 1)) == 0; |
|
611 |
||
612 |
// Plain |
|
613 |
{ |
|
614 |
vh.set(array, i, VALUE_1); |
|
615 |
float x = (float) vh.get(array, i); |
|
616 |
assertEquals(x, VALUE_1, "get float value"); |
|
617 |
} |
|
618 |
||
619 |
||
620 |
if (iAligned) { |
|
621 |
// Volatile |
|
622 |
{ |
|
623 |
vh.setVolatile(array, i, VALUE_2); |
|
624 |
float x = (float) vh.getVolatile(array, i); |
|
625 |
assertEquals(x, VALUE_2, "setVolatile float value"); |
|
626 |
} |
|
627 |
||
628 |
// Lazy |
|
629 |
{ |
|
630 |
vh.setRelease(array, i, VALUE_1); |
|
631 |
float x = (float) vh.getAcquire(array, i); |
|
632 |
assertEquals(x, VALUE_1, "setRelease float value"); |
|
633 |
} |
|
634 |
||
635 |
// Opaque |
|
636 |
{ |
|
637 |
vh.setOpaque(array, i, VALUE_2); |
|
638 |
float x = (float) vh.getOpaque(array, i); |
|
639 |
assertEquals(x, VALUE_2, "setOpaque float value"); |
|
640 |
} |
|
641 |
||
642 |
vh.set(array, i, VALUE_1); |
|
643 |
||
644 |
// Compare |
|
645 |
{ |
|
646 |
boolean r = vh.compareAndSet(array, i, VALUE_1, VALUE_2); |
|
647 |
assertEquals(r, true, "success compareAndSet float"); |
|
648 |
float x = (float) vh.get(array, i); |
|
649 |
assertEquals(x, VALUE_2, "success compareAndSet float value"); |
|
650 |
} |
|
651 |
||
652 |
{ |
|
653 |
boolean r = vh.compareAndSet(array, i, VALUE_1, VALUE_3); |
|
654 |
assertEquals(r, false, "failing compareAndSet float"); |
|
655 |
float x = (float) vh.get(array, i); |
|
656 |
assertEquals(x, VALUE_2, "failing compareAndSet float value"); |
|
657 |
} |
|
658 |
||
659 |
{ |
|
660 |
float r = (float) vh.compareAndExchangeVolatile(array, i, VALUE_2, VALUE_1); |
|
661 |
assertEquals(r, VALUE_2, "success compareAndExchangeVolatile float"); |
|
662 |
float x = (float) vh.get(array, i); |
|
663 |
assertEquals(x, VALUE_1, "success compareAndExchangeVolatile float value"); |
|
664 |
} |
|
665 |
||
666 |
{ |
|
667 |
float r = (float) vh.compareAndExchangeVolatile(array, i, VALUE_2, VALUE_3); |
|
668 |
assertEquals(r, VALUE_1, "failing compareAndExchangeVolatile float"); |
|
669 |
float x = (float) vh.get(array, i); |
|
670 |
assertEquals(x, VALUE_1, "failing compareAndExchangeVolatile float value"); |
|
671 |
} |
|
672 |
||
673 |
{ |
|
674 |
float r = (float) vh.compareAndExchangeAcquire(array, i, VALUE_1, VALUE_2); |
|
675 |
assertEquals(r, VALUE_1, "success compareAndExchangeAcquire float"); |
|
676 |
float x = (float) vh.get(array, i); |
|
677 |
assertEquals(x, VALUE_2, "success compareAndExchangeAcquire float value"); |
|
678 |
} |
|
679 |
||
680 |
{ |
|
681 |
float r = (float) vh.compareAndExchangeAcquire(array, i, VALUE_1, VALUE_3); |
|
682 |
assertEquals(r, VALUE_2, "failing compareAndExchangeAcquire float"); |
|
683 |
float x = (float) vh.get(array, i); |
|
684 |
assertEquals(x, VALUE_2, "failing compareAndExchangeAcquire float value"); |
|
685 |
} |
|
686 |
||
687 |
{ |
|
688 |
float r = (float) vh.compareAndExchangeRelease(array, i, VALUE_2, VALUE_1); |
|
689 |
assertEquals(r, VALUE_2, "success compareAndExchangeRelease float"); |
|
690 |
float x = (float) vh.get(array, i); |
|
691 |
assertEquals(x, VALUE_1, "success compareAndExchangeRelease float value"); |
|
692 |
} |
|
693 |
||
694 |
{ |
|
695 |
float r = (float) vh.compareAndExchangeRelease(array, i, VALUE_2, VALUE_3); |
|
696 |
assertEquals(r, VALUE_1, "failing compareAndExchangeRelease float"); |
|
697 |
float x = (float) vh.get(array, i); |
|
698 |
assertEquals(x, VALUE_1, "failing compareAndExchangeRelease float value"); |
|
699 |
} |
|
700 |
||
701 |
{ |
|
38355
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
702 |
boolean success = false; |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
703 |
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
704 |
success = vh.weakCompareAndSet(array, i, VALUE_1, VALUE_2); |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
705 |
} |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
706 |
assertEquals(success, true, "weakCompareAndSet float"); |
36934 | 707 |
float x = (float) vh.get(array, i); |
708 |
assertEquals(x, VALUE_2, "weakCompareAndSet float value"); |
|
709 |
} |
|
710 |
||
711 |
{ |
|
38355
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
712 |
boolean success = false; |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
713 |
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
714 |
success = vh.weakCompareAndSetAcquire(array, i, VALUE_2, VALUE_1); |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
715 |
} |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
716 |
assertEquals(success, true, "weakCompareAndSetAcquire float"); |
36934 | 717 |
float x = (float) vh.get(array, i); |
718 |
assertEquals(x, VALUE_1, "weakCompareAndSetAcquire float"); |
|
719 |
} |
|
720 |
||
721 |
{ |
|
38355
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
722 |
boolean success = false; |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
723 |
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
724 |
success = vh.weakCompareAndSetRelease(array, i, VALUE_1, VALUE_2); |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
725 |
} |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
726 |
assertEquals(success, true, "weakCompareAndSetRelease float"); |
36934 | 727 |
float x = (float) vh.get(array, i); |
728 |
assertEquals(x, VALUE_2, "weakCompareAndSetRelease float"); |
|
729 |
} |
|
730 |
||
37719
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37668
diff
changeset
|
731 |
{ |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37668
diff
changeset
|
732 |
boolean r = vh.weakCompareAndSetVolatile(array, i, VALUE_2, VALUE_1); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37668
diff
changeset
|
733 |
assertEquals(r, true, "weakCompareAndSetVolatile float"); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37668
diff
changeset
|
734 |
float x = (float) vh.get(array, i); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37668
diff
changeset
|
735 |
assertEquals(x, VALUE_1, "weakCompareAndSetVolatile float value"); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37668
diff
changeset
|
736 |
} |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37668
diff
changeset
|
737 |
|
36934 | 738 |
// Compare set and get |
739 |
{ |
|
37719
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37668
diff
changeset
|
740 |
float o = (float) vh.getAndSet(array, i, VALUE_2); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37668
diff
changeset
|
741 |
assertEquals(o, VALUE_1, "getAndSet float"); |
36934 | 742 |
float x = (float) vh.get(array, i); |
37719
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37668
diff
changeset
|
743 |
assertEquals(x, VALUE_2, "getAndSet float value"); |
36934 | 744 |
} |
745 |
||
746 |
} |
|
747 |
} |
|
748 |
} |
|
749 |
||
750 |
||
751 |
static void testArrayReadWrite(ByteBufferSource bs, VarHandleSource vhs) { |
|
752 |
VarHandle vh = vhs.s; |
|
753 |
ByteBuffer array = bs.s; |
|
754 |
||
755 |
int misalignmentAtZero = array.alignmentOffset(0, SIZE); |
|
756 |
||
757 |
bs.fill((byte) 0xff); |
|
758 |
int length = array.limit() - SIZE + 1; |
|
759 |
for (int i = 0; i < length; i++) { |
|
760 |
boolean iAligned = ((i + misalignmentAtZero) & (SIZE - 1)) == 0; |
|
761 |
||
762 |
// Plain |
|
763 |
{ |
|
764 |
vh.set(array, i, VALUE_1); |
|
765 |
float x = (float) vh.get(array, i); |
|
766 |
assertEquals(x, VALUE_1, "get float value"); |
|
767 |
} |
|
768 |
||
769 |
if (iAligned) { |
|
770 |
// Volatile |
|
771 |
{ |
|
772 |
vh.setVolatile(array, i, VALUE_2); |
|
773 |
float x = (float) vh.getVolatile(array, i); |
|
774 |
assertEquals(x, VALUE_2, "setVolatile float value"); |
|
775 |
} |
|
776 |
||
777 |
// Lazy |
|
778 |
{ |
|
779 |
vh.setRelease(array, i, VALUE_1); |
|
780 |
float x = (float) vh.getAcquire(array, i); |
|
781 |
assertEquals(x, VALUE_1, "setRelease float value"); |
|
782 |
} |
|
783 |
||
784 |
// Opaque |
|
785 |
{ |
|
786 |
vh.setOpaque(array, i, VALUE_2); |
|
787 |
float x = (float) vh.getOpaque(array, i); |
|
788 |
assertEquals(x, VALUE_2, "setOpaque float value"); |
|
789 |
} |
|
790 |
||
791 |
vh.set(array, i, VALUE_1); |
|
792 |
||
793 |
// Compare |
|
794 |
{ |
|
795 |
boolean r = vh.compareAndSet(array, i, VALUE_1, VALUE_2); |
|
796 |
assertEquals(r, true, "success compareAndSet float"); |
|
797 |
float x = (float) vh.get(array, i); |
|
798 |
assertEquals(x, VALUE_2, "success compareAndSet float value"); |
|
799 |
} |
|
800 |
||
801 |
{ |
|
802 |
boolean r = vh.compareAndSet(array, i, VALUE_1, VALUE_3); |
|
803 |
assertEquals(r, false, "failing compareAndSet float"); |
|
804 |
float x = (float) vh.get(array, i); |
|
805 |
assertEquals(x, VALUE_2, "failing compareAndSet float value"); |
|
806 |
} |
|
807 |
||
808 |
{ |
|
809 |
float r = (float) vh.compareAndExchangeVolatile(array, i, VALUE_2, VALUE_1); |
|
810 |
assertEquals(r, VALUE_2, "success compareAndExchangeVolatile float"); |
|
811 |
float x = (float) vh.get(array, i); |
|
812 |
assertEquals(x, VALUE_1, "success compareAndExchangeVolatile float value"); |
|
813 |
} |
|
814 |
||
815 |
{ |
|
816 |
float r = (float) vh.compareAndExchangeVolatile(array, i, VALUE_2, VALUE_3); |
|
817 |
assertEquals(r, VALUE_1, "failing compareAndExchangeVolatile float"); |
|
818 |
float x = (float) vh.get(array, i); |
|
819 |
assertEquals(x, VALUE_1, "failing compareAndExchangeVolatile float value"); |
|
820 |
} |
|
821 |
||
822 |
{ |
|
823 |
float r = (float) vh.compareAndExchangeAcquire(array, i, VALUE_1, VALUE_2); |
|
824 |
assertEquals(r, VALUE_1, "success compareAndExchangeAcquire float"); |
|
825 |
float x = (float) vh.get(array, i); |
|
826 |
assertEquals(x, VALUE_2, "success compareAndExchangeAcquire float value"); |
|
827 |
} |
|
828 |
||
829 |
{ |
|
830 |
float r = (float) vh.compareAndExchangeAcquire(array, i, VALUE_1, VALUE_3); |
|
831 |
assertEquals(r, VALUE_2, "failing compareAndExchangeAcquire float"); |
|
832 |
float x = (float) vh.get(array, i); |
|
833 |
assertEquals(x, VALUE_2, "failing compareAndExchangeAcquire float value"); |
|
834 |
} |
|
835 |
||
836 |
{ |
|
837 |
float r = (float) vh.compareAndExchangeRelease(array, i, VALUE_2, VALUE_1); |
|
838 |
assertEquals(r, VALUE_2, "success compareAndExchangeRelease float"); |
|
839 |
float x = (float) vh.get(array, i); |
|
840 |
assertEquals(x, VALUE_1, "success compareAndExchangeRelease float value"); |
|
841 |
} |
|
842 |
||
843 |
{ |
|
844 |
float r = (float) vh.compareAndExchangeRelease(array, i, VALUE_2, VALUE_3); |
|
845 |
assertEquals(r, VALUE_1, "failing compareAndExchangeRelease float"); |
|
846 |
float x = (float) vh.get(array, i); |
|
847 |
assertEquals(x, VALUE_1, "failing compareAndExchangeRelease float value"); |
|
848 |
} |
|
849 |
||
850 |
{ |
|
38355
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
851 |
boolean success = false; |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
852 |
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
853 |
success = vh.weakCompareAndSet(array, i, VALUE_1, VALUE_2); |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
854 |
} |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
855 |
assertEquals(success, true, "weakCompareAndSet float"); |
36934 | 856 |
float x = (float) vh.get(array, i); |
857 |
assertEquals(x, VALUE_2, "weakCompareAndSet float value"); |
|
858 |
} |
|
859 |
||
860 |
{ |
|
38355
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
861 |
boolean success = false; |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
862 |
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
863 |
success = vh.weakCompareAndSetAcquire(array, i, VALUE_2, VALUE_1); |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
864 |
} |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
865 |
assertEquals(success, true, "weakCompareAndSetAcquire float"); |
36934 | 866 |
float x = (float) vh.get(array, i); |
867 |
assertEquals(x, VALUE_1, "weakCompareAndSetAcquire float"); |
|
868 |
} |
|
869 |
||
870 |
{ |
|
38355
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
871 |
boolean success = false; |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
872 |
for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
873 |
success = vh.weakCompareAndSetRelease(array, i, VALUE_1, VALUE_2); |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
874 |
} |
674cfd9b90cf
8155739: [TESTBUG] VarHandles/Unsafe tests for weakCAS should allow spurious failures
shade
parents:
37343
diff
changeset
|
875 |
assertEquals(success, true, "weakCompareAndSetRelease float"); |
36934 | 876 |
float x = (float) vh.get(array, i); |
877 |
assertEquals(x, VALUE_2, "weakCompareAndSetRelease float"); |
|
878 |
} |
|
879 |
||
37719
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37668
diff
changeset
|
880 |
{ |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37668
diff
changeset
|
881 |
boolean r = vh.weakCompareAndSetVolatile(array, i, VALUE_2, VALUE_1); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37668
diff
changeset
|
882 |
assertEquals(r, true, "weakCompareAndSetVolatile float"); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37668
diff
changeset
|
883 |
float x = (float) vh.get(array, i); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37668
diff
changeset
|
884 |
assertEquals(x, VALUE_1, "weakCompareAndSetVolatile float value"); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37668
diff
changeset
|
885 |
} |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37668
diff
changeset
|
886 |
|
36934 | 887 |
// Compare set and get |
888 |
{ |
|
37719
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37668
diff
changeset
|
889 |
float o = (float) vh.getAndSet(array, i, VALUE_2); |
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37668
diff
changeset
|
890 |
assertEquals(o, VALUE_1, "getAndSet float"); |
36934 | 891 |
float x = (float) vh.get(array, i); |
37719
add11bc0e6e2
8154755: Add a VarHandle weakCompareAndSet with volatile semantics
psandoz
parents:
37668
diff
changeset
|
892 |
assertEquals(x, VALUE_2, "getAndSet float value"); |
36934 | 893 |
} |
894 |
||
895 |
} |
|
896 |
} |
|
897 |
} |
|
898 |
||
899 |
static void testArrayReadOnly(ByteBufferSource bs, VarHandleSource vhs) { |
|
900 |
VarHandle vh = vhs.s; |
|
901 |
ByteBuffer array = bs.s; |
|
902 |
||
903 |
int misalignmentAtZero = array.alignmentOffset(0, SIZE); |
|
904 |
||
905 |
ByteBuffer bb = ByteBuffer.allocate(SIZE); |
|
906 |
bb.order(MemoryMode.BIG_ENDIAN.isSet(vhs.memoryModes) ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN); |
|
907 |
bs.fill(bb.putFloat(0, VALUE_2).array()); |
|
908 |
||
909 |
int length = array.limit() - SIZE + 1; |
|
910 |
for (int i = 0; i < length; i++) { |
|
911 |
boolean iAligned = ((i + misalignmentAtZero) & (SIZE - 1)) == 0; |
|
912 |
||
913 |
float v = MemoryMode.BIG_ENDIAN.isSet(vhs.memoryModes) |
|
914 |
? rotateLeft(VALUE_2, (i % SIZE) << 3) |
|
915 |
: rotateRight(VALUE_2, (i % SIZE) << 3); |
|
916 |
// Plain |
|
917 |
{ |
|
918 |
float x = (float) vh.get(array, i); |
|
919 |
assertEquals(x, v, "get float value"); |
|
920 |
} |
|
921 |
||
922 |
if (iAligned) { |
|
923 |
// Volatile |
|
924 |
{ |
|
925 |
float x = (float) vh.getVolatile(array, i); |
|
926 |
assertEquals(x, v, "getVolatile float value"); |
|
927 |
} |
|
928 |
||
929 |
// Lazy |
|
930 |
{ |
|
931 |
float x = (float) vh.getAcquire(array, i); |
|
932 |
assertEquals(x, v, "getRelease float value"); |
|
933 |
} |
|
934 |
||
935 |
// Opaque |
|
936 |
{ |
|
937 |
float x = (float) vh.getOpaque(array, i); |
|
938 |
assertEquals(x, v, "getOpaque float value"); |
|
939 |
} |
|
940 |
} |
|
941 |
} |
|
942 |
} |
|
943 |
||
944 |
} |
|
945 |