test/jdk/java/lang/invoke/VarHandles/VarHandleTestByteArrayAsShort.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             short x = (short) vh.get(array, ci);
       
   208         });
       
   209 
       
   210         checkNPE(() -> {
       
   211             vh.set(array, ci, VALUE_1);
       
   212         });
       
   213 
       
   214         checkNPE(() -> {
       
   215             short x = (short) vh.getVolatile(array, ci);
       
   216         });
       
   217 
       
   218         checkNPE(() -> {
       
   219             short x = (short) vh.getAcquire(array, ci);
       
   220         });
       
   221 
       
   222         checkNPE(() -> {
       
   223             short x = (short) 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 
       
   239 
       
   240     }
       
   241 
       
   242     static void testArrayNPE(ByteBufferSource bs, VarHandleSource vhs) {
       
   243         VarHandle vh = vhs.s;
       
   244         ByteBuffer array = null;
       
   245         int ci = 1;
       
   246 
       
   247         checkNPE(() -> {
       
   248             short x = (short) vh.get(array, ci);
       
   249         });
       
   250 
       
   251         checkNPE(() -> {
       
   252             vh.set(array, ci, VALUE_1);
       
   253         });
       
   254 
       
   255         checkNPE(() -> {
       
   256             short x = (short) vh.getVolatile(array, ci);
       
   257         });
       
   258 
       
   259         checkNPE(() -> {
       
   260             short x = (short) vh.getAcquire(array, ci);
       
   261         });
       
   262 
       
   263         checkNPE(() -> {
       
   264             short x = (short) vh.getOpaque(array, ci);
       
   265         });
       
   266 
       
   267         checkNPE(() -> {
       
   268             vh.setVolatile(array, ci, VALUE_1);
       
   269         });
       
   270 
       
   271         checkNPE(() -> {
       
   272             vh.setRelease(array, ci, VALUE_1);
       
   273         });
       
   274 
       
   275         checkNPE(() -> {
       
   276             vh.setOpaque(array, ci, VALUE_1);
       
   277         });
       
   278 
       
   279 
       
   280 
       
   281     }
       
   282 
   195     static void testArrayUnsupported(ByteArraySource bs, VarHandleSource vhs) {
   283     static void testArrayUnsupported(ByteArraySource bs, VarHandleSource vhs) {
   196         VarHandle vh = vhs.s;
   284         VarHandle vh = vhs.s;
   197         byte[] array = bs.s;
   285         byte[] array = bs.s;
   198         int ci = 1;
   286         int ci = 1;
   199 
   287