137 |
137 |
138 cases.add(new VarHandleSourceAccessTestCase( |
138 cases.add(new VarHandleSourceAccessTestCase( |
139 "read write", bav, vh, h -> testArrayReadWrite(bas, h), |
139 "read write", bav, vh, h -> testArrayReadWrite(bas, h), |
140 true)); |
140 true)); |
141 cases.add(new VarHandleSourceAccessTestCase( |
141 cases.add(new VarHandleSourceAccessTestCase( |
|
142 "null array", bav, vh, h -> testArrayNPE(bas, h), |
|
143 false)); |
|
144 cases.add(new VarHandleSourceAccessTestCase( |
142 "unsupported", bav, vh, h -> testArrayUnsupported(bas, h), |
145 "unsupported", bav, vh, h -> testArrayUnsupported(bas, h), |
143 false)); |
146 false)); |
144 cases.add(new VarHandleSourceAccessTestCase( |
147 cases.add(new VarHandleSourceAccessTestCase( |
145 "index out of bounds", bav, vh, h -> testArrayIndexOutOfBounds(bas, h), |
148 "index out of bounds", bav, vh, h -> testArrayIndexOutOfBounds(bas, h), |
146 false)); |
149 false)); |
161 "read only", bav, vh, h -> testArrayReadOnly(bbs, h), |
164 "read only", bav, vh, h -> testArrayReadOnly(bbs, h), |
162 true)); |
165 true)); |
163 } |
166 } |
164 |
167 |
165 cases.add(new VarHandleSourceAccessTestCase( |
168 cases.add(new VarHandleSourceAccessTestCase( |
|
169 "null buffer", bav, vh, h -> testArrayNPE(bbs, h), |
|
170 false)); |
|
171 cases.add(new VarHandleSourceAccessTestCase( |
166 "unsupported", bav, vh, h -> testArrayUnsupported(bbs, h), |
172 "unsupported", bav, vh, h -> testArrayUnsupported(bbs, h), |
167 false)); |
173 false)); |
168 cases.add(new VarHandleSourceAccessTestCase( |
174 cases.add(new VarHandleSourceAccessTestCase( |
169 "index out of bounds", bav, vh, h -> testArrayIndexOutOfBounds(bbs, h), |
175 "index out of bounds", bav, vh, h -> testArrayIndexOutOfBounds(bbs, h), |
170 false)); |
176 false)); |
190 atc.testAccess(t); |
196 atc.testAccess(t); |
191 } |
197 } |
192 } |
198 } |
193 |
199 |
194 |
200 |
|
201 static void testArrayNPE(ByteArraySource bs, VarHandleSource vhs) { |
|
202 VarHandle vh = vhs.s; |
|
203 byte[] array = null; |
|
204 int ci = 1; |
|
205 |
|
206 checkNPE(() -> { |
|
207 int x = (int) vh.get(array, ci); |
|
208 }); |
|
209 |
|
210 checkNPE(() -> { |
|
211 vh.set(array, ci, VALUE_1); |
|
212 }); |
|
213 |
|
214 checkNPE(() -> { |
|
215 int x = (int) vh.getVolatile(array, ci); |
|
216 }); |
|
217 |
|
218 checkNPE(() -> { |
|
219 int x = (int) vh.getAcquire(array, ci); |
|
220 }); |
|
221 |
|
222 checkNPE(() -> { |
|
223 int x = (int) vh.getOpaque(array, ci); |
|
224 }); |
|
225 |
|
226 checkNPE(() -> { |
|
227 vh.setVolatile(array, ci, VALUE_1); |
|
228 }); |
|
229 |
|
230 checkNPE(() -> { |
|
231 vh.setRelease(array, ci, VALUE_1); |
|
232 }); |
|
233 |
|
234 checkNPE(() -> { |
|
235 vh.setOpaque(array, ci, VALUE_1); |
|
236 }); |
|
237 |
|
238 checkNPE(() -> { |
|
239 boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2); |
|
240 }); |
|
241 |
|
242 checkNPE(() -> { |
|
243 int r = (int) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1); |
|
244 }); |
|
245 |
|
246 checkNPE(() -> { |
|
247 int r = (int) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1); |
|
248 }); |
|
249 |
|
250 checkNPE(() -> { |
|
251 int r = (int) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1); |
|
252 }); |
|
253 |
|
254 checkNPE(() -> { |
|
255 boolean r = vh.weakCompareAndSetPlain(array, ci, VALUE_1, VALUE_2); |
|
256 }); |
|
257 |
|
258 checkNPE(() -> { |
|
259 boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2); |
|
260 }); |
|
261 |
|
262 checkNPE(() -> { |
|
263 boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2); |
|
264 }); |
|
265 |
|
266 checkNPE(() -> { |
|
267 boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2); |
|
268 }); |
|
269 |
|
270 checkNPE(() -> { |
|
271 int o = (int) vh.getAndSet(array, ci, VALUE_1); |
|
272 }); |
|
273 |
|
274 checkNPE(() -> { |
|
275 int o = (int) vh.getAndSetAcquire(array, ci, VALUE_1); |
|
276 }); |
|
277 |
|
278 checkNPE(() -> { |
|
279 int o = (int) vh.getAndSetRelease(array, ci, VALUE_1); |
|
280 }); |
|
281 |
|
282 checkNPE(() -> { |
|
283 int o = (int) vh.getAndAdd(array, ci, VALUE_1); |
|
284 }); |
|
285 |
|
286 checkNPE(() -> { |
|
287 int o = (int) vh.getAndAddAcquire(array, ci, VALUE_1); |
|
288 }); |
|
289 |
|
290 checkNPE(() -> { |
|
291 int o = (int) vh.getAndAddRelease(array, ci, VALUE_1); |
|
292 }); |
|
293 |
|
294 checkNPE(() -> { |
|
295 int o = (int) vh.getAndBitwiseOr(array, ci, VALUE_1); |
|
296 }); |
|
297 |
|
298 checkNPE(() -> { |
|
299 int o = (int) vh.getAndBitwiseOrAcquire(array, ci, VALUE_1); |
|
300 }); |
|
301 |
|
302 checkNPE(() -> { |
|
303 int o = (int) vh.getAndBitwiseOrRelease(array, ci, VALUE_1); |
|
304 }); |
|
305 |
|
306 checkNPE(() -> { |
|
307 int o = (int) vh.getAndBitwiseAnd(array, ci, VALUE_1); |
|
308 }); |
|
309 |
|
310 checkNPE(() -> { |
|
311 int o = (int) vh.getAndBitwiseAndAcquire(array, ci, VALUE_1); |
|
312 }); |
|
313 |
|
314 checkNPE(() -> { |
|
315 int o = (int) vh.getAndBitwiseAndRelease(array, ci, VALUE_1); |
|
316 }); |
|
317 |
|
318 checkNPE(() -> { |
|
319 int o = (int) vh.getAndBitwiseXor(array, ci, VALUE_1); |
|
320 }); |
|
321 |
|
322 checkNPE(() -> { |
|
323 int o = (int) vh.getAndBitwiseXorAcquire(array, ci, VALUE_1); |
|
324 }); |
|
325 |
|
326 checkNPE(() -> { |
|
327 int o = (int) vh.getAndBitwiseXorRelease(array, ci, VALUE_1); |
|
328 }); |
|
329 } |
|
330 |
|
331 static void testArrayNPE(ByteBufferSource bs, VarHandleSource vhs) { |
|
332 VarHandle vh = vhs.s; |
|
333 ByteBuffer array = null; |
|
334 int ci = 1; |
|
335 |
|
336 checkNPE(() -> { |
|
337 int x = (int) vh.get(array, ci); |
|
338 }); |
|
339 |
|
340 checkNPE(() -> { |
|
341 vh.set(array, ci, VALUE_1); |
|
342 }); |
|
343 |
|
344 checkNPE(() -> { |
|
345 int x = (int) vh.getVolatile(array, ci); |
|
346 }); |
|
347 |
|
348 checkNPE(() -> { |
|
349 int x = (int) vh.getAcquire(array, ci); |
|
350 }); |
|
351 |
|
352 checkNPE(() -> { |
|
353 int x = (int) vh.getOpaque(array, ci); |
|
354 }); |
|
355 |
|
356 checkNPE(() -> { |
|
357 vh.setVolatile(array, ci, VALUE_1); |
|
358 }); |
|
359 |
|
360 checkNPE(() -> { |
|
361 vh.setRelease(array, ci, VALUE_1); |
|
362 }); |
|
363 |
|
364 checkNPE(() -> { |
|
365 vh.setOpaque(array, ci, VALUE_1); |
|
366 }); |
|
367 |
|
368 checkNPE(() -> { |
|
369 boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2); |
|
370 }); |
|
371 |
|
372 checkNPE(() -> { |
|
373 int r = (int) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1); |
|
374 }); |
|
375 |
|
376 checkNPE(() -> { |
|
377 int r = (int) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1); |
|
378 }); |
|
379 |
|
380 checkNPE(() -> { |
|
381 int r = (int) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1); |
|
382 }); |
|
383 |
|
384 checkNPE(() -> { |
|
385 boolean r = vh.weakCompareAndSetPlain(array, ci, VALUE_1, VALUE_2); |
|
386 }); |
|
387 |
|
388 checkNPE(() -> { |
|
389 boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2); |
|
390 }); |
|
391 |
|
392 checkNPE(() -> { |
|
393 boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2); |
|
394 }); |
|
395 |
|
396 checkNPE(() -> { |
|
397 boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2); |
|
398 }); |
|
399 |
|
400 checkNPE(() -> { |
|
401 int o = (int) vh.getAndSet(array, ci, VALUE_1); |
|
402 }); |
|
403 |
|
404 checkNPE(() -> { |
|
405 int o = (int) vh.getAndSetAcquire(array, ci, VALUE_1); |
|
406 }); |
|
407 |
|
408 checkNPE(() -> { |
|
409 int o = (int) vh.getAndSetRelease(array, ci, VALUE_1); |
|
410 }); |
|
411 |
|
412 checkNPE(() -> { |
|
413 int o = (int) vh.getAndAdd(array, ci, VALUE_1); |
|
414 }); |
|
415 |
|
416 checkNPE(() -> { |
|
417 int o = (int) vh.getAndAddAcquire(array, ci, VALUE_1); |
|
418 }); |
|
419 |
|
420 checkNPE(() -> { |
|
421 int o = (int) vh.getAndAddRelease(array, ci, VALUE_1); |
|
422 }); |
|
423 |
|
424 checkNPE(() -> { |
|
425 int o = (int) vh.getAndBitwiseOr(array, ci, VALUE_1); |
|
426 }); |
|
427 |
|
428 checkNPE(() -> { |
|
429 int o = (int) vh.getAndBitwiseOrAcquire(array, ci, VALUE_1); |
|
430 }); |
|
431 |
|
432 checkNPE(() -> { |
|
433 int o = (int) vh.getAndBitwiseOrRelease(array, ci, VALUE_1); |
|
434 }); |
|
435 |
|
436 checkNPE(() -> { |
|
437 int o = (int) vh.getAndBitwiseAnd(array, ci, VALUE_1); |
|
438 }); |
|
439 |
|
440 checkNPE(() -> { |
|
441 int o = (int) vh.getAndBitwiseAndAcquire(array, ci, VALUE_1); |
|
442 }); |
|
443 |
|
444 checkNPE(() -> { |
|
445 int o = (int) vh.getAndBitwiseAndRelease(array, ci, VALUE_1); |
|
446 }); |
|
447 |
|
448 checkNPE(() -> { |
|
449 int o = (int) vh.getAndBitwiseXor(array, ci, VALUE_1); |
|
450 }); |
|
451 |
|
452 checkNPE(() -> { |
|
453 int o = (int) vh.getAndBitwiseXorAcquire(array, ci, VALUE_1); |
|
454 }); |
|
455 |
|
456 checkNPE(() -> { |
|
457 int o = (int) vh.getAndBitwiseXorRelease(array, ci, VALUE_1); |
|
458 }); |
|
459 } |
|
460 |
195 static void testArrayUnsupported(ByteArraySource bs, VarHandleSource vhs) { |
461 static void testArrayUnsupported(ByteArraySource bs, VarHandleSource vhs) { |
196 VarHandle vh = vhs.s; |
462 VarHandle vh = vhs.s; |
197 byte[] array = bs.s; |
463 byte[] array = bs.s; |
198 int ci = 1; |
464 int ci = 1; |
199 |
465 |