test/jdk/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsFloat.java
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.
   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             float x = (float) vh.get(array, ci);
       
   208         });
       
   209 
       
   210         checkNPE(() -> {
       
   211             vh.set(array, ci, VALUE_1);
       
   212         });
       
   213 
       
   214         checkNPE(() -> {
       
   215             float x = (float) vh.getVolatile(array, ci);
       
   216         });
       
   217 
       
   218         checkNPE(() -> {
       
   219             float x = (float) vh.getAcquire(array, ci);
       
   220         });
       
   221 
       
   222         checkNPE(() -> {
       
   223             float x = (float) 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             float r = (float) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
       
   244         });
       
   245 
       
   246         checkNPE(() -> {
       
   247             float r = (float) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1);
       
   248         });
       
   249 
       
   250         checkNPE(() -> {
       
   251             float r = (float) 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             float o = (float) vh.getAndSet(array, ci, VALUE_1);
       
   272         });
       
   273 
       
   274         checkNPE(() -> {
       
   275             float o = (float) vh.getAndSetAcquire(array, ci, VALUE_1);
       
   276         });
       
   277 
       
   278         checkNPE(() -> {
       
   279             float o = (float) vh.getAndSetRelease(array, ci, VALUE_1);
       
   280         });
       
   281 
       
   282 
       
   283     }
       
   284 
       
   285     static void testArrayNPE(ByteBufferSource bs, VarHandleSource vhs) {
       
   286         VarHandle vh = vhs.s;
       
   287         ByteBuffer array = null;
       
   288         int ci = 1;
       
   289 
       
   290         checkNPE(() -> {
       
   291             float x = (float) vh.get(array, ci);
       
   292         });
       
   293 
       
   294         checkNPE(() -> {
       
   295             vh.set(array, ci, VALUE_1);
       
   296         });
       
   297 
       
   298         checkNPE(() -> {
       
   299             float x = (float) vh.getVolatile(array, ci);
       
   300         });
       
   301 
       
   302         checkNPE(() -> {
       
   303             float x = (float) vh.getAcquire(array, ci);
       
   304         });
       
   305 
       
   306         checkNPE(() -> {
       
   307             float x = (float) vh.getOpaque(array, ci);
       
   308         });
       
   309 
       
   310         checkNPE(() -> {
       
   311             vh.setVolatile(array, ci, VALUE_1);
       
   312         });
       
   313 
       
   314         checkNPE(() -> {
       
   315             vh.setRelease(array, ci, VALUE_1);
       
   316         });
       
   317 
       
   318         checkNPE(() -> {
       
   319             vh.setOpaque(array, ci, VALUE_1);
       
   320         });
       
   321 
       
   322         checkNPE(() -> {
       
   323             boolean r = vh.compareAndSet(array, ci, VALUE_1, VALUE_2);
       
   324         });
       
   325 
       
   326         checkNPE(() -> {
       
   327             float r = (float) vh.compareAndExchange(array, ci, VALUE_2, VALUE_1);
       
   328         });
       
   329 
       
   330         checkNPE(() -> {
       
   331             float r = (float) vh.compareAndExchangeAcquire(array, ci, VALUE_2, VALUE_1);
       
   332         });
       
   333 
       
   334         checkNPE(() -> {
       
   335             float r = (float) vh.compareAndExchangeRelease(array, ci, VALUE_2, VALUE_1);
       
   336         });
       
   337 
       
   338         checkNPE(() -> {
       
   339             boolean r = vh.weakCompareAndSetPlain(array, ci, VALUE_1, VALUE_2);
       
   340         });
       
   341 
       
   342         checkNPE(() -> {
       
   343             boolean r = vh.weakCompareAndSet(array, ci, VALUE_1, VALUE_2);
       
   344         });
       
   345 
       
   346         checkNPE(() -> {
       
   347             boolean r = vh.weakCompareAndSetAcquire(array, ci, VALUE_1, VALUE_2);
       
   348         });
       
   349 
       
   350         checkNPE(() -> {
       
   351             boolean r = vh.weakCompareAndSetRelease(array, ci, VALUE_1, VALUE_2);
       
   352         });
       
   353 
       
   354         checkNPE(() -> {
       
   355             float o = (float) vh.getAndSet(array, ci, VALUE_1);
       
   356         });
       
   357 
       
   358         checkNPE(() -> {
       
   359             float o = (float) vh.getAndSetAcquire(array, ci, VALUE_1);
       
   360         });
       
   361 
       
   362         checkNPE(() -> {
       
   363             float o = (float) vh.getAndSetRelease(array, ci, VALUE_1);
       
   364         });
       
   365 
       
   366 
       
   367     }
       
   368 
   195     static void testArrayUnsupported(ByteArraySource bs, VarHandleSource vhs) {
   369     static void testArrayUnsupported(ByteArraySource bs, VarHandleSource vhs) {
   196         VarHandle vh = vhs.s;
   370         VarHandle vh = vhs.s;
   197         byte[] array = bs.s;
   371         byte[] array = bs.s;
   198         int ci = 1;
   372         int ci = 1;
   199 
   373