test/jdk/java/lang/invoke/VarHandles/X-VarHandleTestByteArrayView.java.template
changeset 48710 38872bed90e0
parent 47216 71c04702a3d5
child 52914 4fa75d8ad418
equal deleted inserted replaced
48709:2d9dad1b821a 48710:38872bed90e0
     1 /*
     1 /*
     2  * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
   169 
   169 
   170                         cases.add(new VarHandleSourceAccessTestCase(
   170                         cases.add(new VarHandleSourceAccessTestCase(
   171                                 "read write", bav, vh, h -> testArrayReadWrite(bas, h),
   171                                 "read write", bav, vh, h -> testArrayReadWrite(bas, h),
   172                                 true));
   172                                 true));
   173                         cases.add(new VarHandleSourceAccessTestCase(
   173                         cases.add(new VarHandleSourceAccessTestCase(
       
   174                                 "null array", bav, vh, h -> testArrayNPE(bas, h),
       
   175                                 false));
       
   176                         cases.add(new VarHandleSourceAccessTestCase(
   174                                 "unsupported", bav, vh, h -> testArrayUnsupported(bas, h),
   177                                 "unsupported", bav, vh, h -> testArrayUnsupported(bas, h),
   175                                 false));
   178                                 false));
   176                         cases.add(new VarHandleSourceAccessTestCase(
   179                         cases.add(new VarHandleSourceAccessTestCase(
   177                                 "index out of bounds", bav, vh, h -> testArrayIndexOutOfBounds(bas, h),
   180                                 "index out of bounds", bav, vh, h -> testArrayIndexOutOfBounds(bas, h),
   178                                 false));
   181                                 false));
   193                                     "read only", bav, vh, h -> testArrayReadOnly(bbs, h),
   196                                     "read only", bav, vh, h -> testArrayReadOnly(bbs, h),
   194                                     true));
   197                                     true));
   195                         }
   198                         }
   196 
   199 
   197                         cases.add(new VarHandleSourceAccessTestCase(
   200                         cases.add(new VarHandleSourceAccessTestCase(
       
   201                                 "null buffer", bav, vh, h -> testArrayNPE(bbs, h),
       
   202                                 false));
       
   203                         cases.add(new VarHandleSourceAccessTestCase(
   198                                 "unsupported", bav, vh, h -> testArrayUnsupported(bbs, h),
   204                                 "unsupported", bav, vh, h -> testArrayUnsupported(bbs, h),
   199                                 false));
   205                                 false));
   200                         cases.add(new VarHandleSourceAccessTestCase(
   206                         cases.add(new VarHandleSourceAccessTestCase(
   201                                 "index out of bounds", bav, vh, h -> testArrayIndexOutOfBounds(bbs, h),
   207                                 "index out of bounds", bav, vh, h -> testArrayIndexOutOfBounds(bbs, h),
   202                                 false));
   208                                 false));
   222             atc.testAccess(t);
   228             atc.testAccess(t);
   223         }
   229         }
   224     }
   230     }
   225 
   231 
   226 
   232 
       
   233     static void testArrayNPE(ByteArraySource bs, VarHandleSource vhs) {
       
   234         VarHandle vh = vhs.s;
       
   235         byte[] array = null;
       
   236         int ci = 1;
       
   237 
       
   238         checkNPE(() -> {
       
   239             $type$ x = ($type$) vh.get(array, ci);
       
   240         });
       
   241 
       
   242         checkNPE(() -> {
       
   243             vh.set(array, ci, VALUE_1);
       
   244         });
       
   245 
       
   246         checkNPE(() -> {
       
   247             $type$ x = ($type$) vh.getVolatile(array, ci);
       
   248         });
       
   249 
       
   250         checkNPE(() -> {
       
   251             $type$ x = ($type$) vh.getAcquire(array, ci);
       
   252         });
       
   253 
       
   254         checkNPE(() -> {
       
   255             $type$ x = ($type$) vh.getOpaque(array, ci);
       
   256         });
       
   257 
       
   258         checkNPE(() -> {
       
   259             vh.setVolatile(array, ci, VALUE_1);
       
   260         });
       
   261 
       
   262         checkNPE(() -> {
       
   263             vh.setRelease(array, ci, VALUE_1);
       
   264         });
       
   265 
       
   266         checkNPE(() -> {
       
   267             vh.setOpaque(array, ci, VALUE_1);
       
   268         });
       
   269 
       
   270 #if[CAS]
       
   271         checkNPE(() -> {
       
   272             boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2);
       
   273         });
       
   274 
       
   275         checkNPE(() -> {
       
   276             $type$ r = ($type$) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
       
   277         });
       
   278 
       
   279         checkNPE(() -> {
       
   280             $type$ r = ($type$) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1);
       
   281         });
       
   282 
       
   283         checkNPE(() -> {
       
   284             $type$ r = ($type$) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1);
       
   285         });
       
   286 
       
   287         checkNPE(() -> {
       
   288             boolean r = vh.weakCompareAndSetPlain(array, ci, VALUE_1, VALUE_2);
       
   289         });
       
   290 
       
   291         checkNPE(() -> {
       
   292             boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2);
       
   293         });
       
   294 
       
   295         checkNPE(() -> {
       
   296             boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2);
       
   297         });
       
   298 
       
   299         checkNPE(() -> {
       
   300             boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2);
       
   301         });
       
   302 
       
   303         checkNPE(() -> {
       
   304             $type$ o = ($type$) vh.getAndSet(array, ci, VALUE_1);
       
   305         });
       
   306 
       
   307         checkNPE(() -> {
       
   308             $type$ o = ($type$) vh.getAndSetAcquire(array, ci, VALUE_1);
       
   309         });
       
   310 
       
   311         checkNPE(() -> {
       
   312             $type$ o = ($type$) vh.getAndSetRelease(array, ci, VALUE_1);
       
   313         });
       
   314 #end[CAS]
       
   315 
       
   316 #if[AtomicAdd]
       
   317         checkNPE(() -> {
       
   318             $type$ o = ($type$) vh.getAndAdd(array, ci, VALUE_1);
       
   319         });
       
   320 
       
   321         checkNPE(() -> {
       
   322             $type$ o = ($type$) vh.getAndAddAcquire(array, ci, VALUE_1);
       
   323         });
       
   324 
       
   325         checkNPE(() -> {
       
   326             $type$ o = ($type$) vh.getAndAddRelease(array, ci, VALUE_1);
       
   327         });
       
   328 #end[AtomicAdd]
       
   329 
       
   330 #if[Bitwise]
       
   331         checkNPE(() -> {
       
   332             $type$ o = ($type$) vh.getAndBitwiseOr(array, ci, VALUE_1);
       
   333         });
       
   334 
       
   335         checkNPE(() -> {
       
   336             $type$ o = ($type$) vh.getAndBitwiseOrAcquire(array, ci, VALUE_1);
       
   337         });
       
   338 
       
   339         checkNPE(() -> {
       
   340             $type$ o = ($type$) vh.getAndBitwiseOrRelease(array, ci, VALUE_1);
       
   341         });
       
   342 
       
   343         checkNPE(() -> {
       
   344             $type$ o = ($type$) vh.getAndBitwiseAnd(array, ci, VALUE_1);
       
   345         });
       
   346 
       
   347         checkNPE(() -> {
       
   348             $type$ o = ($type$) vh.getAndBitwiseAndAcquire(array, ci, VALUE_1);
       
   349         });
       
   350 
       
   351         checkNPE(() -> {
       
   352             $type$ o = ($type$) vh.getAndBitwiseAndRelease(array, ci, VALUE_1);
       
   353         });
       
   354 
       
   355         checkNPE(() -> {
       
   356             $type$ o = ($type$) vh.getAndBitwiseXor(array, ci, VALUE_1);
       
   357         });
       
   358 
       
   359         checkNPE(() -> {
       
   360             $type$ o = ($type$) vh.getAndBitwiseXorAcquire(array, ci, VALUE_1);
       
   361         });
       
   362 
       
   363         checkNPE(() -> {
       
   364             $type$ o = ($type$) vh.getAndBitwiseXorRelease(array, ci, VALUE_1);
       
   365         });
       
   366 #end[Bitwise]
       
   367     }
       
   368 
       
   369     static void testArrayNPE(ByteBufferSource bs, VarHandleSource vhs) {
       
   370         VarHandle vh = vhs.s;
       
   371         ByteBuffer array = null;
       
   372         int ci = 1;
       
   373 
       
   374         checkNPE(() -> {
       
   375             $type$ x = ($type$) vh.get(array, ci);
       
   376         });
       
   377 
       
   378         checkNPE(() -> {
       
   379             vh.set(array, ci, VALUE_1);
       
   380         });
       
   381 
       
   382         checkNPE(() -> {
       
   383             $type$ x = ($type$) vh.getVolatile(array, ci);
       
   384         });
       
   385 
       
   386         checkNPE(() -> {
       
   387             $type$ x = ($type$) vh.getAcquire(array, ci);
       
   388         });
       
   389 
       
   390         checkNPE(() -> {
       
   391             $type$ x = ($type$) vh.getOpaque(array, ci);
       
   392         });
       
   393 
       
   394         checkNPE(() -> {
       
   395             vh.setVolatile(array, ci, VALUE_1);
       
   396         });
       
   397 
       
   398         checkNPE(() -> {
       
   399             vh.setRelease(array, ci, VALUE_1);
       
   400         });
       
   401 
       
   402         checkNPE(() -> {
       
   403             vh.setOpaque(array, ci, VALUE_1);
       
   404         });
       
   405 
       
   406 #if[CAS]
       
   407         checkNPE(() -> {
       
   408             boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2);
       
   409         });
       
   410 
       
   411         checkNPE(() -> {
       
   412             $type$ r = ($type$) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
       
   413         });
       
   414 
       
   415         checkNPE(() -> {
       
   416             $type$ r = ($type$) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1);
       
   417         });
       
   418 
       
   419         checkNPE(() -> {
       
   420             $type$ r = ($type$) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1);
       
   421         });
       
   422 
       
   423         checkNPE(() -> {
       
   424             boolean r = vh.weakCompareAndSetPlain(array, ci, VALUE_1, VALUE_2);
       
   425         });
       
   426 
       
   427         checkNPE(() -> {
       
   428             boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2);
       
   429         });
       
   430 
       
   431         checkNPE(() -> {
       
   432             boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2);
       
   433         });
       
   434 
       
   435         checkNPE(() -> {
       
   436             boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2);
       
   437         });
       
   438 
       
   439         checkNPE(() -> {
       
   440             $type$ o = ($type$) vh.getAndSet(array, ci, VALUE_1);
       
   441         });
       
   442 
       
   443         checkNPE(() -> {
       
   444             $type$ o = ($type$) vh.getAndSetAcquire(array, ci, VALUE_1);
       
   445         });
       
   446 
       
   447         checkNPE(() -> {
       
   448             $type$ o = ($type$) vh.getAndSetRelease(array, ci, VALUE_1);
       
   449         });
       
   450 #end[CAS]
       
   451 
       
   452 #if[AtomicAdd]
       
   453         checkNPE(() -> {
       
   454             $type$ o = ($type$) vh.getAndAdd(array, ci, VALUE_1);
       
   455         });
       
   456 
       
   457         checkNPE(() -> {
       
   458             $type$ o = ($type$) vh.getAndAddAcquire(array, ci, VALUE_1);
       
   459         });
       
   460 
       
   461         checkNPE(() -> {
       
   462             $type$ o = ($type$) vh.getAndAddRelease(array, ci, VALUE_1);
       
   463         });
       
   464 #end[AtomicAdd]
       
   465 
       
   466 #if[Bitwise]
       
   467         checkNPE(() -> {
       
   468             $type$ o = ($type$) vh.getAndBitwiseOr(array, ci, VALUE_1);
       
   469         });
       
   470 
       
   471         checkNPE(() -> {
       
   472             $type$ o = ($type$) vh.getAndBitwiseOrAcquire(array, ci, VALUE_1);
       
   473         });
       
   474 
       
   475         checkNPE(() -> {
       
   476             $type$ o = ($type$) vh.getAndBitwiseOrRelease(array, ci, VALUE_1);
       
   477         });
       
   478 
       
   479         checkNPE(() -> {
       
   480             $type$ o = ($type$) vh.getAndBitwiseAnd(array, ci, VALUE_1);
       
   481         });
       
   482 
       
   483         checkNPE(() -> {
       
   484             $type$ o = ($type$) vh.getAndBitwiseAndAcquire(array, ci, VALUE_1);
       
   485         });
       
   486 
       
   487         checkNPE(() -> {
       
   488             $type$ o = ($type$) vh.getAndBitwiseAndRelease(array, ci, VALUE_1);
       
   489         });
       
   490 
       
   491         checkNPE(() -> {
       
   492             $type$ o = ($type$) vh.getAndBitwiseXor(array, ci, VALUE_1);
       
   493         });
       
   494 
       
   495         checkNPE(() -> {
       
   496             $type$ o = ($type$) vh.getAndBitwiseXorAcquire(array, ci, VALUE_1);
       
   497         });
       
   498 
       
   499         checkNPE(() -> {
       
   500             $type$ o = ($type$) vh.getAndBitwiseXorRelease(array, ci, VALUE_1);
       
   501         });
       
   502 #end[Bitwise]
       
   503     }
       
   504 
   227     static void testArrayUnsupported(ByteArraySource bs, VarHandleSource vhs) {
   505     static void testArrayUnsupported(ByteArraySource bs, VarHandleSource vhs) {
   228         VarHandle vh = vhs.s;
   506         VarHandle vh = vhs.s;
   229         byte[] array = bs.s;
   507         byte[] array = bs.s;
   230         int ci = 1;
   508         int ci = 1;
   231 
   509