test/jdk/java/lang/invoke/VarHandles/X-VarHandleTestAccess.java.template
changeset 49788 5375d426822a
parent 47216 71c04702a3d5
child 52914 4fa75d8ad418
equal deleted inserted replaced
49787:99b627637911 49788:5375d426822a
    58 
    58 
    59     VarHandle vhStaticFinalField;
    59     VarHandle vhStaticFinalField;
    60 
    60 
    61     VarHandle vhArray;
    61     VarHandle vhArray;
    62 
    62 
       
    63 #if[String]
       
    64     VarHandle vhArrayObject;
       
    65 #end[String]
       
    66 
    63     @BeforeClass
    67     @BeforeClass
    64     public void setup() throws Exception {
    68     public void setup() throws Exception {
    65         vhFinalField = MethodHandles.lookup().findVarHandle(
    69         vhFinalField = MethodHandles.lookup().findVarHandle(
    66                 VarHandleTestAccess$Type$.class, "final_v", $type$.class);
    70                 VarHandleTestAccess$Type$.class, "final_v", $type$.class);
    67 
    71 
    73 
    77 
    74         vhStaticField = MethodHandles.lookup().findStaticVarHandle(
    78         vhStaticField = MethodHandles.lookup().findStaticVarHandle(
    75             VarHandleTestAccess$Type$.class, "static_v", $type$.class);
    79             VarHandleTestAccess$Type$.class, "static_v", $type$.class);
    76 
    80 
    77         vhArray = MethodHandles.arrayElementVarHandle($type$[].class);
    81         vhArray = MethodHandles.arrayElementVarHandle($type$[].class);
       
    82 #if[String]
       
    83         vhArrayObject = MethodHandles.arrayElementVarHandle(Object[].class);
       
    84 #end[String]
    78     }
    85     }
    79 
    86 
    80 
    87 
    81     @DataProvider
    88     @DataProvider
    82     public Object[][] varHandlesProvider() throws Exception {
    89     public Object[][] varHandlesProvider() throws Exception {
   234                                               vhStaticField, VarHandleTestAccess$Type$::testStaticFieldUnsupported,
   241                                               vhStaticField, VarHandleTestAccess$Type$::testStaticFieldUnsupported,
   235                                               false));
   242                                               false));
   236 
   243 
   237         cases.add(new VarHandleAccessTestCase("Array",
   244         cases.add(new VarHandleAccessTestCase("Array",
   238                                               vhArray, VarHandleTestAccess$Type$::testArray));
   245                                               vhArray, VarHandleTestAccess$Type$::testArray));
       
   246 #if[String]
       
   247         cases.add(new VarHandleAccessTestCase("Array Object[]",
       
   248                                               vhArrayObject, VarHandleTestAccess$Type$::testArray));
       
   249 #end[String]
   239         cases.add(new VarHandleAccessTestCase("Array unsupported",
   250         cases.add(new VarHandleAccessTestCase("Array unsupported",
   240                                               vhArray, VarHandleTestAccess$Type$::testArrayUnsupported,
   251                                               vhArray, VarHandleTestAccess$Type$::testArrayUnsupported,
   241                                               false));
   252                                               false));
   242         cases.add(new VarHandleAccessTestCase("Array index out of bounds",
   253         cases.add(new VarHandleAccessTestCase("Array index out of bounds",
   243                                               vhArray, VarHandleTestAccess$Type$::testArrayIndexOutOfBounds,
   254                                               vhArray, VarHandleTestAccess$Type$::testArrayIndexOutOfBounds,
   244                                               false));
   255                                               false));
   245 
   256 #if[String]
       
   257         cases.add(new VarHandleAccessTestCase("Array store exception",
       
   258                                               vhArrayObject, VarHandleTestAccess$Type$::testArrayStoreException,
       
   259                                               false));
       
   260 #end[String]
   246         // Work around issue with jtreg summary reporting which truncates
   261         // Work around issue with jtreg summary reporting which truncates
   247         // the String result of Object.toString to 30 characters, hence
   262         // the String result of Object.toString to 30 characters, hence
   248         // the first dummy argument
   263         // the first dummy argument
   249         return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
   264         return cases.stream().map(tc -> new Object[]{tc.toString(), tc}).toArray(Object[][]::new);
   250     }
   265     }
  1821                 $type$ o = ($type$) vh.getAndBitwiseXorRelease(array, ci, $value1$);
  1836                 $type$ o = ($type$) vh.getAndBitwiseXorRelease(array, ci, $value1$);
  1822             });
  1837             });
  1823 #end[Bitwise]
  1838 #end[Bitwise]
  1824         }
  1839         }
  1825     }
  1840     }
       
  1841 
       
  1842 #if[String]
       
  1843     static void testArrayStoreException(VarHandle vh) throws Throwable {
       
  1844         Object[] array = new $type$[10];
       
  1845         Arrays.fill(array, $value1$);
       
  1846         Object value = new Object();
       
  1847 
       
  1848         // Set
       
  1849         checkASE(() -> {
       
  1850             vh.set(array, 0, value);
       
  1851         });
       
  1852 
       
  1853         // SetVolatile
       
  1854         checkASE(() -> {
       
  1855             vh.setVolatile(array, 0, value);
       
  1856         });
       
  1857 
       
  1858         // SetOpaque
       
  1859         checkASE(() -> {
       
  1860             vh.setOpaque(array, 0, value);
       
  1861         });
       
  1862 
       
  1863         // SetRelease
       
  1864         checkASE(() -> {
       
  1865             vh.setRelease(array, 0, value);
       
  1866         });
       
  1867 
       
  1868         // CompareAndSet
       
  1869         checkASE(() -> { // receiver reference class
       
  1870             boolean r = vh.compareAndSet(array, 0, $value1$, value);
       
  1871         });
       
  1872 
       
  1873         // WeakCompareAndSet
       
  1874         checkASE(() -> { // receiver reference class
       
  1875             boolean r = vh.weakCompareAndSetPlain(array, 0, $value1$, value);
       
  1876         });
       
  1877 
       
  1878         // WeakCompareAndSetVolatile
       
  1879         checkASE(() -> { // receiver reference class
       
  1880             boolean r = vh.weakCompareAndSet(array, 0, $value1$, value);
       
  1881         });
       
  1882 
       
  1883         // WeakCompareAndSetAcquire
       
  1884         checkASE(() -> { // receiver reference class
       
  1885             boolean r = vh.weakCompareAndSetAcquire(array, 0, $value1$, value);
       
  1886         });
       
  1887 
       
  1888         // WeakCompareAndSetRelease
       
  1889         checkASE(() -> { // receiver reference class
       
  1890             boolean r = vh.weakCompareAndSetRelease(array, 0, $value1$, value);
       
  1891         });
       
  1892 
       
  1893         // CompareAndExchange
       
  1894         checkASE(() -> { // receiver reference class
       
  1895             $type$ x = ($type$) vh.compareAndExchange(array, 0, $value1$, value);
       
  1896         });
       
  1897 
       
  1898         // CompareAndExchangeAcquire
       
  1899         checkASE(() -> { // receiver reference class
       
  1900             $type$ x = ($type$) vh.compareAndExchangeAcquire(array, 0, $value1$, value);
       
  1901         });
       
  1902 
       
  1903         // CompareAndExchangeRelease
       
  1904         checkASE(() -> { // receiver reference class
       
  1905             $type$ x = ($type$) vh.compareAndExchangeRelease(array, 0, $value1$, value);
       
  1906         });
       
  1907 
       
  1908         // GetAndSet
       
  1909         checkASE(() -> { // receiver reference class
       
  1910             $type$ x = ($type$) vh.getAndSet(array, 0, value);
       
  1911         });
       
  1912 
       
  1913         // GetAndSetAcquire
       
  1914         checkASE(() -> { // receiver reference class
       
  1915             $type$ x = ($type$) vh.getAndSetAcquire(array, 0, value);
       
  1916         });
       
  1917 
       
  1918         // GetAndSetRelease
       
  1919         checkASE(() -> { // receiver reference class
       
  1920             $type$ x = ($type$) vh.getAndSetRelease(array, 0, value);
       
  1921         });
       
  1922     }
       
  1923 #end[String]
  1826 }
  1924 }
  1827 
  1925