< prev index next >

test/jdk/java/lang/invoke/VarHandles/X-VarHandleTestByteArrayView.java.template

Print this page
rev 52865 : [mq]: 8210031


  37 import java.nio.ByteBuffer;
  38 import java.nio.ByteOrder;
  39 import java.util.ArrayList;
  40 import java.util.Arrays;
  41 import java.util.EnumSet;
  42 import java.util.List;
  43 
  44 import static org.testng.Assert.*;
  45 
  46 public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest {
  47     static final int SIZE = $BoxType$.BYTES;
  48 
  49     static final $type$ VALUE_1 = $value1$;
  50 
  51     static final $type$ VALUE_2 = $value2$;
  52 
  53     static final $type$ VALUE_3 = $value3$;
  54 
  55 
  56     @Override
  57     public void setupVarHandleSources() {
  58         // Combinations of VarHandle byte[] or ByteBuffer
  59         vhss = new ArrayList<>();
  60         for (MemoryMode endianess : Arrays.asList(MemoryMode.BIG_ENDIAN, MemoryMode.LITTLE_ENDIAN)) {
  61 
  62             ByteOrder bo = endianess == MemoryMode.BIG_ENDIAN
  63                     ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN;












  64             VarHandleSource aeh = new VarHandleSource(
  65                     MethodHandles.byteArrayViewVarHandle($type$[].class, bo),
  66                     endianess, MemoryMode.READ_WRITE);
  67             vhss.add(aeh);
  68 
  69             VarHandleSource bbh = new VarHandleSource(
  70                     MethodHandles.byteBufferViewVarHandle($type$[].class, bo),
  71                     endianess, MemoryMode.READ_WRITE);
  72             vhss.add(bbh);
  73         }

  74     }
  75 



























  76 
  77     @Test(dataProvider = "varHandlesProvider")
  78     public void testIsAccessModeSupported(VarHandleSource vhs) {
  79         VarHandle vh = vhs.s;
  80 
  81         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET));
  82         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET));
  83 
  84         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_VOLATILE));
  85         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_VOLATILE));
  86         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_ACQUIRE));
  87         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_RELEASE));
  88         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_OPAQUE));
  89         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE));
  90 
  91 #if[CAS]
  92         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
  93         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
  94         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
  95         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));




  37 import java.nio.ByteBuffer;
  38 import java.nio.ByteOrder;
  39 import java.util.ArrayList;
  40 import java.util.Arrays;
  41 import java.util.EnumSet;
  42 import java.util.List;
  43 
  44 import static org.testng.Assert.*;
  45 
  46 public class VarHandleTestByteArrayAs$Type$ extends VarHandleBaseByteArrayTest {
  47     static final int SIZE = $BoxType$.BYTES;
  48 
  49     static final $type$ VALUE_1 = $value1$;
  50 
  51     static final $type$ VALUE_2 = $value2$;
  52 
  53     static final $type$ VALUE_3 = $value3$;
  54 
  55 
  56     @Override
  57     public List<VarHandleSource> setupVarHandleSources(boolean same) {
  58         // Combinations of VarHandle byte[] or ByteBuffer
  59         List<VarHandleSource> vhss = new ArrayList<>();
  60         for (MemoryMode endianess : List.of(MemoryMode.BIG_ENDIAN, MemoryMode.LITTLE_ENDIAN)) {
  61 
  62             ByteOrder bo = endianess == MemoryMode.BIG_ENDIAN
  63                     ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN;
  64 
  65             Class<?> arrayType;
  66             if (same) {
  67                 arrayType = $type$[].class;
  68             }
  69             else {
  70 #if[int]
  71                 arrayType = long[].class;
  72 #else[int]
  73                 arrayType = int[].class;
  74 #end[int]
  75             }
  76             VarHandleSource aeh = new VarHandleSource(
  77                     MethodHandles.byteArrayViewVarHandle(arrayType, bo),
  78                     endianess, MemoryMode.READ_WRITE);
  79             vhss.add(aeh);
  80 
  81             VarHandleSource bbh = new VarHandleSource(
  82                     MethodHandles.byteBufferViewVarHandle(arrayType, bo),
  83                     endianess, MemoryMode.READ_WRITE);
  84             vhss.add(bbh);
  85         }
  86         return vhss;
  87     }
  88 
  89     @Test
  90     public void testEqualsAndHashCode() {
  91         VarHandle[] vhs1 = setupVarHandleSources(true).stream().
  92             map(vhs -> vhs.s).toArray(VarHandle[]::new);
  93         VarHandle[] vhs2 = setupVarHandleSources(true).stream().
  94             map(vhs -> vhs.s).toArray(VarHandle[]::new);
  95 
  96         for (int i = 0; i < vhs1.length; i++) {
  97             for (int j = 0; j < vhs1.length; j++) {
  98                 if (i == j) {
  99                     assertEquals(vhs1[i], vhs1[i]);
 100                     assertEquals(vhs1[i], vhs2[i]);
 101                     assertEquals(vhs1[i].hashCode(), vhs2[i].hashCode());
 102                 }
 103                 else {
 104                     assertNotEquals(vhs1[i], vhs1[j]);
 105                     assertNotEquals(vhs1[i], vhs2[j]);
 106                 }
 107             }
 108         }
 109 
 110         VarHandle[] vhs3 = setupVarHandleSources(false).stream().
 111             map(vhs -> vhs.s).toArray(VarHandle[]::new);
 112         for (int i = 0; i < vhs1.length; i++) {
 113             assertNotEquals(vhs1[i], vhs3[i]);
 114         }
 115     }
 116 
 117     @Test(dataProvider = "varHandlesProvider")
 118     public void testIsAccessModeSupported(VarHandleSource vhs) {
 119         VarHandle vh = vhs.s;
 120 
 121         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET));
 122         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET));
 123 
 124         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_VOLATILE));
 125         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_VOLATILE));
 126         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_ACQUIRE));
 127         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_RELEASE));
 128         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.GET_OPAQUE));
 129         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.SET_OPAQUE));
 130 
 131 #if[CAS]
 132         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_SET));
 133         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE));
 134         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_ACQUIRE));
 135         assertTrue(vh.isAccessModeSupported(VarHandle.AccessMode.COMPARE_AND_EXCHANGE_RELEASE));


< prev index next >