119 |
119 |
120 |
120 |
121 static void testInstanceField(VarHandleTestMethodHandleAccessByte recv, Handles hs) throws Throwable { |
121 static void testInstanceField(VarHandleTestMethodHandleAccessByte recv, Handles hs) throws Throwable { |
122 // Plain |
122 // Plain |
123 { |
123 { |
124 hs.get(TestAccessMode.SET).invokeExact(recv, (byte)1); |
124 hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01); |
125 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); |
125 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); |
126 assertEquals(x, (byte)1, "set byte value"); |
126 assertEquals(x, (byte)0x01, "set byte value"); |
127 } |
127 } |
128 |
128 |
129 |
129 |
130 // Volatile |
130 // Volatile |
131 { |
131 { |
132 hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, (byte)2); |
132 hs.get(TestAccessMode.SET_VOLATILE).invokeExact(recv, (byte)0x23); |
133 byte x = (byte) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv); |
133 byte x = (byte) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(recv); |
134 assertEquals(x, (byte)2, "setVolatile byte value"); |
134 assertEquals(x, (byte)0x23, "setVolatile byte value"); |
135 } |
135 } |
136 |
136 |
137 // Lazy |
137 // Lazy |
138 { |
138 { |
139 hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, (byte)1); |
139 hs.get(TestAccessMode.SET_RELEASE).invokeExact(recv, (byte)0x01); |
140 byte x = (byte) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv); |
140 byte x = (byte) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(recv); |
141 assertEquals(x, (byte)1, "setRelease byte value"); |
141 assertEquals(x, (byte)0x01, "setRelease byte value"); |
142 } |
142 } |
143 |
143 |
144 // Opaque |
144 // Opaque |
145 { |
145 { |
146 hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, (byte)2); |
146 hs.get(TestAccessMode.SET_OPAQUE).invokeExact(recv, (byte)0x23); |
147 byte x = (byte) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv); |
147 byte x = (byte) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(recv); |
148 assertEquals(x, (byte)2, "setOpaque byte value"); |
148 assertEquals(x, (byte)0x23, "setOpaque byte value"); |
149 } |
149 } |
150 |
150 |
151 |
151 hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01); |
|
152 |
|
153 // Compare |
|
154 { |
|
155 boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, (byte)0x01, (byte)0x23); |
|
156 assertEquals(r, true, "success compareAndSet byte"); |
|
157 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); |
|
158 assertEquals(x, (byte)0x23, "success compareAndSet byte value"); |
|
159 } |
|
160 |
|
161 { |
|
162 boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(recv, (byte)0x01, (byte)0x45); |
|
163 assertEquals(r, false, "failing compareAndSet byte"); |
|
164 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); |
|
165 assertEquals(x, (byte)0x23, "failing compareAndSet byte value"); |
|
166 } |
|
167 |
|
168 { |
|
169 byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(recv, (byte)0x23, (byte)0x01); |
|
170 assertEquals(r, (byte)0x23, "success compareAndExchangeVolatile byte"); |
|
171 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); |
|
172 assertEquals(x, (byte)0x01, "success compareAndExchangeVolatile byte value"); |
|
173 } |
|
174 |
|
175 { |
|
176 byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(recv, (byte)0x23, (byte)0x45); |
|
177 assertEquals(r, (byte)0x01, "failing compareAndExchangeVolatile byte"); |
|
178 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); |
|
179 assertEquals(x, (byte)0x01, "failing compareAndExchangeVolatile byte value"); |
|
180 } |
|
181 |
|
182 { |
|
183 byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, (byte)0x01, (byte)0x23); |
|
184 assertEquals(r, (byte)0x01, "success compareAndExchangeAcquire byte"); |
|
185 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); |
|
186 assertEquals(x, (byte)0x23, "success compareAndExchangeAcquire byte value"); |
|
187 } |
|
188 |
|
189 { |
|
190 byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(recv, (byte)0x01, (byte)0x45); |
|
191 assertEquals(r, (byte)0x23, "failing compareAndExchangeAcquire byte"); |
|
192 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); |
|
193 assertEquals(x, (byte)0x23, "failing compareAndExchangeAcquire byte value"); |
|
194 } |
|
195 |
|
196 { |
|
197 byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, (byte)0x23, (byte)0x01); |
|
198 assertEquals(r, (byte)0x23, "success compareAndExchangeRelease byte"); |
|
199 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); |
|
200 assertEquals(x, (byte)0x01, "success compareAndExchangeRelease byte value"); |
|
201 } |
|
202 |
|
203 { |
|
204 byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(recv, (byte)0x23, (byte)0x45); |
|
205 assertEquals(r, (byte)0x01, "failing compareAndExchangeRelease byte"); |
|
206 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); |
|
207 assertEquals(x, (byte)0x01, "failing compareAndExchangeRelease byte value"); |
|
208 } |
|
209 |
|
210 { |
|
211 boolean success = false; |
|
212 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
|
213 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(recv, (byte)0x01, (byte)0x23); |
|
214 } |
|
215 assertEquals(success, true, "weakCompareAndSet byte"); |
|
216 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); |
|
217 assertEquals(x, (byte)0x23, "weakCompareAndSet byte value"); |
|
218 } |
|
219 |
|
220 { |
|
221 boolean success = false; |
|
222 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
|
223 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(recv, (byte)0x23, (byte)0x01); |
|
224 } |
|
225 assertEquals(success, true, "weakCompareAndSetAcquire byte"); |
|
226 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); |
|
227 assertEquals(x, (byte)0x01, "weakCompareAndSetAcquire byte"); |
|
228 } |
|
229 |
|
230 { |
|
231 boolean success = false; |
|
232 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
|
233 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(recv, (byte)0x01, (byte)0x23); |
|
234 } |
|
235 assertEquals(success, true, "weakCompareAndSetRelease byte"); |
|
236 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); |
|
237 assertEquals(x, (byte)0x23, "weakCompareAndSetRelease byte"); |
|
238 } |
|
239 |
|
240 { |
|
241 boolean success = false; |
|
242 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
|
243 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(recv, (byte)0x23, (byte)0x01); |
|
244 } |
|
245 assertEquals(success, true, "weakCompareAndSetVolatile byte"); |
|
246 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); |
|
247 assertEquals(x, (byte)0x01, "weakCompareAndSetVolatile byte"); |
|
248 } |
|
249 |
|
250 // Compare set and get |
|
251 { |
|
252 byte o = (byte) hs.get(TestAccessMode.GET_AND_SET).invokeExact(recv, (byte)0x23); |
|
253 assertEquals(o, (byte)0x01, "getAndSet byte"); |
|
254 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(recv); |
|
255 assertEquals(x, (byte)0x23, "getAndSet byte value"); |
|
256 } |
|
257 |
|
258 hs.get(TestAccessMode.SET).invokeExact(recv, (byte)0x01); |
|
259 |
|
260 // get and add, add and get |
|
261 { |
|
262 byte o = (byte) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(recv, (byte)0x45); |
|
263 assertEquals(o, (byte)0x01, "getAndAdd byte"); |
|
264 byte c = (byte) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(recv, (byte)0x45); |
|
265 assertEquals(c, (byte)((byte)0x01 + (byte)0x45 + (byte)0x45), "getAndAdd byte value"); |
|
266 } |
152 } |
267 } |
153 |
268 |
154 static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccessByte recv, Handles hs) throws Throwable { |
269 static void testInstanceFieldUnsupported(VarHandleTestMethodHandleAccessByte recv, Handles hs) throws Throwable { |
155 for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) { |
270 |
156 checkUOE(am, () -> { |
|
157 boolean r = (boolean) hs.get(am).invokeExact(recv, (byte)1, (byte)2); |
|
158 }); |
|
159 } |
|
160 |
|
161 for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) { |
|
162 checkUOE(am, () -> { |
|
163 byte r = (byte) hs.get(am).invokeExact(recv, (byte)1, (byte)2); |
|
164 }); |
|
165 } |
|
166 |
|
167 for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) { |
|
168 checkUOE(am, () -> { |
|
169 byte r = (byte) hs.get(am).invokeExact(recv, (byte)1); |
|
170 }); |
|
171 } |
|
172 |
|
173 for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) { |
|
174 checkUOE(am, () -> { |
|
175 byte r = (byte) hs.get(am).invokeExact(recv, (byte)1); |
|
176 }); |
|
177 } |
|
178 } |
271 } |
179 |
272 |
180 |
273 |
181 static void testStaticField(Handles hs) throws Throwable { |
274 static void testStaticField(Handles hs) throws Throwable { |
182 // Plain |
275 // Plain |
183 { |
276 { |
184 hs.get(TestAccessMode.SET).invokeExact((byte)1); |
277 hs.get(TestAccessMode.SET).invokeExact((byte)0x01); |
185 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); |
278 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); |
186 assertEquals(x, (byte)1, "set byte value"); |
279 assertEquals(x, (byte)0x01, "set byte value"); |
187 } |
280 } |
188 |
281 |
189 |
282 |
190 // Volatile |
283 // Volatile |
191 { |
284 { |
192 hs.get(TestAccessMode.SET_VOLATILE).invokeExact((byte)2); |
285 hs.get(TestAccessMode.SET_VOLATILE).invokeExact((byte)0x23); |
193 byte x = (byte) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(); |
286 byte x = (byte) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(); |
194 assertEquals(x, (byte)2, "setVolatile byte value"); |
287 assertEquals(x, (byte)0x23, "setVolatile byte value"); |
195 } |
288 } |
196 |
289 |
197 // Lazy |
290 // Lazy |
198 { |
291 { |
199 hs.get(TestAccessMode.SET_RELEASE).invokeExact((byte)1); |
292 hs.get(TestAccessMode.SET_RELEASE).invokeExact((byte)0x01); |
200 byte x = (byte) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(); |
293 byte x = (byte) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(); |
201 assertEquals(x, (byte)1, "setRelease byte value"); |
294 assertEquals(x, (byte)0x01, "setRelease byte value"); |
202 } |
295 } |
203 |
296 |
204 // Opaque |
297 // Opaque |
205 { |
298 { |
206 hs.get(TestAccessMode.SET_OPAQUE).invokeExact((byte)2); |
299 hs.get(TestAccessMode.SET_OPAQUE).invokeExact((byte)0x23); |
207 byte x = (byte) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(); |
300 byte x = (byte) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(); |
208 assertEquals(x, (byte)2, "setOpaque byte value"); |
301 assertEquals(x, (byte)0x23, "setOpaque byte value"); |
209 } |
302 } |
210 |
303 |
211 |
304 hs.get(TestAccessMode.SET).invokeExact((byte)0x01); |
|
305 |
|
306 // Compare |
|
307 { |
|
308 boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact((byte)0x01, (byte)0x23); |
|
309 assertEquals(r, true, "success compareAndSet byte"); |
|
310 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); |
|
311 assertEquals(x, (byte)0x23, "success compareAndSet byte value"); |
|
312 } |
|
313 |
|
314 { |
|
315 boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact((byte)0x01, (byte)0x45); |
|
316 assertEquals(r, false, "failing compareAndSet byte"); |
|
317 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); |
|
318 assertEquals(x, (byte)0x23, "failing compareAndSet byte value"); |
|
319 } |
|
320 |
|
321 { |
|
322 byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact((byte)0x23, (byte)0x01); |
|
323 assertEquals(r, (byte)0x23, "success compareAndExchangeVolatile byte"); |
|
324 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); |
|
325 assertEquals(x, (byte)0x01, "success compareAndExchangeVolatile byte value"); |
|
326 } |
|
327 |
|
328 { |
|
329 byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact((byte)0x23, (byte)0x45); |
|
330 assertEquals(r, (byte)0x01, "failing compareAndExchangeVolatile byte"); |
|
331 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); |
|
332 assertEquals(x, (byte)0x01, "failing compareAndExchangeVolatile byte value"); |
|
333 } |
|
334 |
|
335 { |
|
336 byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact((byte)0x01, (byte)0x23); |
|
337 assertEquals(r, (byte)0x01, "success compareAndExchangeAcquire byte"); |
|
338 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); |
|
339 assertEquals(x, (byte)0x23, "success compareAndExchangeAcquire byte value"); |
|
340 } |
|
341 |
|
342 { |
|
343 byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact((byte)0x01, (byte)0x45); |
|
344 assertEquals(r, (byte)0x23, "failing compareAndExchangeAcquire byte"); |
|
345 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); |
|
346 assertEquals(x, (byte)0x23, "failing compareAndExchangeAcquire byte value"); |
|
347 } |
|
348 |
|
349 { |
|
350 byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact((byte)0x23, (byte)0x01); |
|
351 assertEquals(r, (byte)0x23, "success compareAndExchangeRelease byte"); |
|
352 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); |
|
353 assertEquals(x, (byte)0x01, "success compareAndExchangeRelease byte value"); |
|
354 } |
|
355 |
|
356 { |
|
357 byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact((byte)0x23, (byte)0x45); |
|
358 assertEquals(r, (byte)0x01, "failing compareAndExchangeRelease byte"); |
|
359 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); |
|
360 assertEquals(x, (byte)0x01, "failing compareAndExchangeRelease byte value"); |
|
361 } |
|
362 |
|
363 { |
|
364 boolean success = false; |
|
365 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
|
366 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact((byte)0x01, (byte)0x23); |
|
367 } |
|
368 assertEquals(success, true, "weakCompareAndSet byte"); |
|
369 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); |
|
370 assertEquals(x, (byte)0x23, "weakCompareAndSet byte value"); |
|
371 } |
|
372 |
|
373 { |
|
374 boolean success = false; |
|
375 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
|
376 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact((byte)0x23, (byte)0x01); |
|
377 } |
|
378 assertEquals(success, true, "weakCompareAndSetAcquire byte"); |
|
379 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); |
|
380 assertEquals(x, (byte)0x01, "weakCompareAndSetAcquire byte"); |
|
381 } |
|
382 |
|
383 { |
|
384 boolean success = false; |
|
385 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
|
386 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact((byte)0x01, (byte)0x23); |
|
387 } |
|
388 assertEquals(success, true, "weakCompareAndSetRelease byte"); |
|
389 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); |
|
390 assertEquals(x, (byte)0x23, "weakCompareAndSetRelease byte"); |
|
391 } |
|
392 |
|
393 { |
|
394 boolean success = false; |
|
395 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
|
396 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact((byte)0x23, (byte)0x01); |
|
397 } |
|
398 assertEquals(success, true, "weakCompareAndSetVolatile byte"); |
|
399 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); |
|
400 assertEquals(x, (byte)0x01, "weakCompareAndSetVolatile byte"); |
|
401 } |
|
402 |
|
403 // Compare set and get |
|
404 { |
|
405 byte o = (byte) hs.get(TestAccessMode.GET_AND_SET).invokeExact( (byte)0x23); |
|
406 assertEquals(o, (byte)0x01, "getAndSet byte"); |
|
407 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(); |
|
408 assertEquals(x, (byte)0x23, "getAndSet byte value"); |
|
409 } |
|
410 |
|
411 hs.get(TestAccessMode.SET).invokeExact((byte)0x01); |
|
412 |
|
413 // get and add, add and get |
|
414 { |
|
415 byte o = (byte) hs.get(TestAccessMode.GET_AND_ADD).invokeExact( (byte)0x45); |
|
416 assertEquals(o, (byte)0x01, "getAndAdd byte"); |
|
417 byte c = (byte) hs.get(TestAccessMode.ADD_AND_GET).invokeExact((byte)0x45); |
|
418 assertEquals(c, (byte)((byte)0x01 + (byte)0x45 + (byte)0x45), "getAndAdd byte value"); |
|
419 } |
212 } |
420 } |
213 |
421 |
214 static void testStaticFieldUnsupported(Handles hs) throws Throwable { |
422 static void testStaticFieldUnsupported(Handles hs) throws Throwable { |
215 for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) { |
423 |
216 checkUOE(am, () -> { |
|
217 boolean r = (boolean) hs.get(am).invokeExact((byte)1, (byte)2); |
|
218 }); |
|
219 } |
|
220 |
|
221 for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) { |
|
222 checkUOE(am, () -> { |
|
223 byte r = (byte) hs.get(am).invokeExact((byte)1, (byte)2); |
|
224 }); |
|
225 } |
|
226 |
|
227 for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) { |
|
228 checkUOE(am, () -> { |
|
229 byte r = (byte) hs.get(am).invokeExact((byte)1); |
|
230 }); |
|
231 } |
|
232 |
|
233 for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) { |
|
234 checkUOE(am, () -> { |
|
235 byte r = (byte) hs.get(am).invokeExact((byte)1); |
|
236 }); |
|
237 } |
|
238 } |
424 } |
239 |
425 |
240 |
426 |
241 static void testArray(Handles hs) throws Throwable { |
427 static void testArray(Handles hs) throws Throwable { |
242 byte[] array = new byte[10]; |
428 byte[] array = new byte[10]; |
243 |
429 |
244 for (int i = 0; i < array.length; i++) { |
430 for (int i = 0; i < array.length; i++) { |
245 // Plain |
431 // Plain |
246 { |
432 { |
247 hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)1); |
433 hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01); |
248 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); |
434 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); |
249 assertEquals(x, (byte)1, "get byte value"); |
435 assertEquals(x, (byte)0x01, "get byte value"); |
250 } |
436 } |
251 |
437 |
252 |
438 |
253 // Volatile |
439 // Volatile |
254 { |
440 { |
255 hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, (byte)2); |
441 hs.get(TestAccessMode.SET_VOLATILE).invokeExact(array, i, (byte)0x23); |
256 byte x = (byte) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i); |
442 byte x = (byte) hs.get(TestAccessMode.GET_VOLATILE).invokeExact(array, i); |
257 assertEquals(x, (byte)2, "setVolatile byte value"); |
443 assertEquals(x, (byte)0x23, "setVolatile byte value"); |
258 } |
444 } |
259 |
445 |
260 // Lazy |
446 // Lazy |
261 { |
447 { |
262 hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, (byte)1); |
448 hs.get(TestAccessMode.SET_RELEASE).invokeExact(array, i, (byte)0x01); |
263 byte x = (byte) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i); |
449 byte x = (byte) hs.get(TestAccessMode.GET_ACQUIRE).invokeExact(array, i); |
264 assertEquals(x, (byte)1, "setRelease byte value"); |
450 assertEquals(x, (byte)0x01, "setRelease byte value"); |
265 } |
451 } |
266 |
452 |
267 // Opaque |
453 // Opaque |
268 { |
454 { |
269 hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, (byte)2); |
455 hs.get(TestAccessMode.SET_OPAQUE).invokeExact(array, i, (byte)0x23); |
270 byte x = (byte) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i); |
456 byte x = (byte) hs.get(TestAccessMode.GET_OPAQUE).invokeExact(array, i); |
271 assertEquals(x, (byte)2, "setOpaque byte value"); |
457 assertEquals(x, (byte)0x23, "setOpaque byte value"); |
272 } |
458 } |
273 |
459 |
274 |
460 hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01); |
|
461 |
|
462 // Compare |
|
463 { |
|
464 boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, (byte)0x01, (byte)0x23); |
|
465 assertEquals(r, true, "success compareAndSet byte"); |
|
466 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); |
|
467 assertEquals(x, (byte)0x23, "success compareAndSet byte value"); |
|
468 } |
|
469 |
|
470 { |
|
471 boolean r = (boolean) hs.get(TestAccessMode.COMPARE_AND_SET).invokeExact(array, i, (byte)0x01, (byte)0x45); |
|
472 assertEquals(r, false, "failing compareAndSet byte"); |
|
473 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); |
|
474 assertEquals(x, (byte)0x23, "failing compareAndSet byte value"); |
|
475 } |
|
476 |
|
477 { |
|
478 byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(array, i, (byte)0x23, (byte)0x01); |
|
479 assertEquals(r, (byte)0x23, "success compareAndExchangeVolatile byte"); |
|
480 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); |
|
481 assertEquals(x, (byte)0x01, "success compareAndExchangeVolatile byte value"); |
|
482 } |
|
483 |
|
484 { |
|
485 byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_VOLATILE).invokeExact(array, i, (byte)0x23, (byte)0x45); |
|
486 assertEquals(r, (byte)0x01, "failing compareAndExchangeVolatile byte"); |
|
487 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); |
|
488 assertEquals(x, (byte)0x01, "failing compareAndExchangeVolatile byte value"); |
|
489 } |
|
490 |
|
491 { |
|
492 byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, (byte)0x01, (byte)0x23); |
|
493 assertEquals(r, (byte)0x01, "success compareAndExchangeAcquire byte"); |
|
494 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); |
|
495 assertEquals(x, (byte)0x23, "success compareAndExchangeAcquire byte value"); |
|
496 } |
|
497 |
|
498 { |
|
499 byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_ACQUIRE).invokeExact(array, i, (byte)0x01, (byte)0x45); |
|
500 assertEquals(r, (byte)0x23, "failing compareAndExchangeAcquire byte"); |
|
501 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); |
|
502 assertEquals(x, (byte)0x23, "failing compareAndExchangeAcquire byte value"); |
|
503 } |
|
504 |
|
505 { |
|
506 byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, (byte)0x23, (byte)0x01); |
|
507 assertEquals(r, (byte)0x23, "success compareAndExchangeRelease byte"); |
|
508 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); |
|
509 assertEquals(x, (byte)0x01, "success compareAndExchangeRelease byte value"); |
|
510 } |
|
511 |
|
512 { |
|
513 byte r = (byte) hs.get(TestAccessMode.COMPARE_AND_EXCHANGE_RELEASE).invokeExact(array, i, (byte)0x23, (byte)0x45); |
|
514 assertEquals(r, (byte)0x01, "failing compareAndExchangeRelease byte"); |
|
515 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); |
|
516 assertEquals(x, (byte)0x01, "failing compareAndExchangeRelease byte value"); |
|
517 } |
|
518 |
|
519 { |
|
520 boolean success = false; |
|
521 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
|
522 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET).invokeExact(array, i, (byte)0x01, (byte)0x23); |
|
523 } |
|
524 assertEquals(success, true, "weakCompareAndSet byte"); |
|
525 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); |
|
526 assertEquals(x, (byte)0x23, "weakCompareAndSet byte value"); |
|
527 } |
|
528 |
|
529 { |
|
530 boolean success = false; |
|
531 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
|
532 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_ACQUIRE).invokeExact(array, i, (byte)0x23, (byte)0x01); |
|
533 } |
|
534 assertEquals(success, true, "weakCompareAndSetAcquire byte"); |
|
535 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); |
|
536 assertEquals(x, (byte)0x01, "weakCompareAndSetAcquire byte"); |
|
537 } |
|
538 |
|
539 { |
|
540 boolean success = false; |
|
541 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
|
542 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_RELEASE).invokeExact(array, i, (byte)0x01, (byte)0x23); |
|
543 } |
|
544 assertEquals(success, true, "weakCompareAndSetRelease byte"); |
|
545 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); |
|
546 assertEquals(x, (byte)0x23, "weakCompareAndSetRelease byte"); |
|
547 } |
|
548 |
|
549 { |
|
550 boolean success = false; |
|
551 for (int c = 0; c < WEAK_ATTEMPTS && !success; c++) { |
|
552 success = (boolean) hs.get(TestAccessMode.WEAK_COMPARE_AND_SET_VOLATILE).invokeExact(array, i, (byte)0x23, (byte)0x01); |
|
553 } |
|
554 assertEquals(success, true, "weakCompareAndSetVolatile byte"); |
|
555 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); |
|
556 assertEquals(x, (byte)0x01, "weakCompareAndSetVolatile byte"); |
|
557 } |
|
558 |
|
559 // Compare set and get |
|
560 { |
|
561 byte o = (byte) hs.get(TestAccessMode.GET_AND_SET).invokeExact(array, i, (byte)0x23); |
|
562 assertEquals(o, (byte)0x01, "getAndSet byte"); |
|
563 byte x = (byte) hs.get(TestAccessMode.GET).invokeExact(array, i); |
|
564 assertEquals(x, (byte)0x23, "getAndSet byte value"); |
|
565 } |
|
566 |
|
567 hs.get(TestAccessMode.SET).invokeExact(array, i, (byte)0x01); |
|
568 |
|
569 // get and add, add and get |
|
570 { |
|
571 byte o = (byte) hs.get(TestAccessMode.GET_AND_ADD).invokeExact(array, i, (byte)0x45); |
|
572 assertEquals(o, (byte)0x01, "getAndAdd byte"); |
|
573 byte c = (byte) hs.get(TestAccessMode.ADD_AND_GET).invokeExact(array, i, (byte)0x45); |
|
574 assertEquals(c, (byte)((byte)0x01 + (byte)0x45 + (byte)0x45), "getAndAdd byte value"); |
|
575 } |
275 } |
576 } |
276 } |
577 } |
277 |
578 |
278 static void testArrayUnsupported(Handles hs) throws Throwable { |
579 static void testArrayUnsupported(Handles hs) throws Throwable { |
279 byte[] array = new byte[10]; |
580 byte[] array = new byte[10]; |
280 |
581 |
281 final int i = 0; |
582 final int i = 0; |
282 for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_SET)) { |
583 |
283 checkUOE(am, () -> { |
|
284 boolean r = (boolean) hs.get(am).invokeExact(array, i, (byte)1, (byte)2); |
|
285 }); |
|
286 } |
|
287 |
|
288 for (TestAccessMode am : testAccessModesOfType(TestAccessType.COMPARE_AND_EXCHANGE)) { |
|
289 checkUOE(am, () -> { |
|
290 byte r = (byte) hs.get(am).invokeExact(array, i, (byte)1, (byte)2); |
|
291 }); |
|
292 } |
|
293 |
|
294 for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_SET)) { |
|
295 checkUOE(am, () -> { |
|
296 byte r = (byte) hs.get(am).invokeExact(array, i, (byte)1); |
|
297 }); |
|
298 } |
|
299 |
|
300 for (TestAccessMode am : testAccessModesOfType(TestAccessType.GET_AND_ADD)) { |
|
301 checkUOE(am, () -> { |
|
302 byte o = (byte) hs.get(am).invokeExact(array, i, (byte)1); |
|
303 }); |
|
304 } |
|
305 } |
584 } |
306 |
585 |
307 static void testArrayIndexOutOfBounds(Handles hs) throws Throwable { |
586 static void testArrayIndexOutOfBounds(Handles hs) throws Throwable { |
308 byte[] array = new byte[10]; |
587 byte[] array = new byte[10]; |
309 |
588 |