< prev index next >

test/jdk/java/foreign/TestMemoryHandleAsUnsigned.java

Print this page

  8  *
  9  *  This code is distributed in the hope that it will be useful, but WITHOUT
 10  *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  *  version 2 for more details (a copy is included in the LICENSE file that
 13  *  accompanied this code).
 14  *
 15  *  You should have received a copy of the GNU General Public License version
 16  *  2 along with this work; if not, write to the Free Software Foundation,
 17  *  Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  *   Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  *  or visit www.oracle.com if you need additional information or have any
 21  *  questions.
 22  *
 23  */
 24 
 25 import jdk.incubator.foreign.MemoryHandles;
 26 import jdk.incubator.foreign.MemoryLayout;
 27 import jdk.incubator.foreign.MemoryLayout.PathElement;
 28 import jdk.incubator.foreign.MemoryLayouts;
 29 import jdk.incubator.foreign.MemorySegment;
 30 import java.lang.invoke.VarHandle;

 31 import java.util.Arrays;
 32 import java.util.stream.IntStream;
 33 import java.util.stream.LongStream;
 34 
 35 import jdk.incubator.foreign.ResourceScope;

 36 import org.testng.annotations.*;
 37 import static java.nio.ByteOrder.BIG_ENDIAN;
 38 import static org.testng.Assert.*;
 39 
 40 /*
 41  * @test
 42  * @run testng TestMemoryHandleAsUnsigned
 43  */
 44 
 45 public class TestMemoryHandleAsUnsigned {
 46 
 47     @DataProvider(name = "unsignedIntToByteData")
 48     public Object[][] unsignedIntToByteData() {
 49         return IntStream.range(0, 256)
 50                 .mapToObj(v -> new Object[] { v }).toArray(Object[][]::new);
 51     }
 52 
 53     @Test(dataProvider = "unsignedIntToByteData")
 54     public void testUnsignedIntToByte(int intValue) {
 55         byte byteValue = (byte) (intValue & 0xFF);
 56 
 57         MemoryLayout layout = MemoryLayouts.BITS_8_BE;
 58         VarHandle byteHandle = layout.varHandle(byte.class);
 59         VarHandle intHandle = MemoryHandles.asUnsigned(byteHandle, int.class);
 60 
 61         try (ResourceScope scope = ResourceScope.newConfinedScope()) {
 62             MemorySegment segment = MemorySegment.allocateNative(layout, scope);
 63             intHandle.set(segment, intValue);
 64             int expectedIntValue = Byte.toUnsignedInt(byteValue);
 65             assertEquals((int) intHandle.get(segment), expectedIntValue);
 66             assertEquals((byte) byteHandle.get(segment), byteValue);
 67         }
 68     }
 69 
 70     @DataProvider(name = "unsignedLongToByteData")
 71     public Object[][] unsignedLongToByteData() {
 72         return LongStream.range(0L, 256L)
 73                 .mapToObj(v -> new Object[] { v }).toArray(Object[][]::new);
 74     }
 75 
 76     @Test(dataProvider = "unsignedLongToByteData")
 77     public void testUnsignedLongToByte(long longValue) {
 78         byte byteValue = (byte) (longValue & 0xFFL);
 79 
 80         MemoryLayout layout = MemoryLayouts.BITS_8_BE;
 81         VarHandle byteHandle = layout.varHandle(byte.class);
 82         VarHandle longHandle = MemoryHandles.asUnsigned(byteHandle, long.class);
 83 
 84         try (ResourceScope scope = ResourceScope.newConfinedScope()) {
 85             MemorySegment segment = MemorySegment.allocateNative(layout, scope);
 86             longHandle.set(segment, longValue);
 87             long expectedLongValue = Byte.toUnsignedLong(byteValue);
 88             assertEquals((long) longHandle.get(segment), expectedLongValue);
 89             assertEquals((byte) byteHandle.get(segment), byteValue);
 90         }
 91     }
 92 
 93     @DataProvider(name = "unsignedIntToShortData")
 94     public Object[][] unsignedIntToShortData() {
 95         return IntStream.range(0, 65_536).filter(i -> i % 99 == 0)
 96                 .mapToObj(v -> new Object[] { v }).toArray(Object[][]::new);
 97     }
 98 
 99     @Test(dataProvider = "unsignedIntToShortData")
100     public void testUnsignedIntToShort(int intValue) {
101         short shortValue = (short) (intValue & 0xFFFF);
102 
103         MemoryLayout layout = MemoryLayouts.BITS_16_BE;
104         VarHandle shortHandle = layout.varHandle(short.class);
105         VarHandle intHandle = MemoryHandles.asUnsigned(shortHandle, int.class);
106 
107         try (ResourceScope scope = ResourceScope.newConfinedScope()) {
108             MemorySegment segment = MemorySegment.allocateNative(layout, scope);
109             intHandle.set(segment, intValue);
110             int expectedIntValue = Short.toUnsignedInt(shortValue);
111             assertEquals((int) intHandle.get(segment), expectedIntValue);
112             assertEquals((short) shortHandle.get(segment), shortValue);
113         }
114     }
115 
116     @DataProvider(name = "unsignedLongToShortData")
117     public Object[][] unsignedLongToShortData() {
118         return LongStream.range(0L, 65_536L).filter(i -> i % 99 == 0)
119                 .mapToObj(v -> new Object[] { v }).toArray(Object[][]::new);
120     }
121 
122     @Test(dataProvider = "unsignedLongToShortData")
123     public void testUnsignedLongToShort(long longValue) {
124         short shortValue = (short) (longValue & 0xFFFFL);
125 
126         MemoryLayout layout = MemoryLayouts.BITS_16_BE;
127         VarHandle shortHandle = layout.varHandle(short.class);
128         VarHandle longHandle = MemoryHandles.asUnsigned(shortHandle, long.class);
129 
130         try (ResourceScope scope = ResourceScope.newConfinedScope()) {
131             MemorySegment segment = MemorySegment.allocateNative(layout, scope);
132             longHandle.set(segment, longValue);
133             long expectedLongValue = Short.toUnsignedLong(shortValue);
134             assertEquals((long) longHandle.get(segment), expectedLongValue);
135             assertEquals((short) shortHandle.get(segment), shortValue);
136         }
137     }
138 
139     @DataProvider(name = "unsignedLongToIntData")
140     public Object[][] unsignedLongToIntData() {
141         // some boundary values
142         long[] l = new long[] { Long.MAX_VALUE, Long.MIN_VALUE,
143                 Short.MAX_VALUE - 1L, Short.MAX_VALUE, Short.MAX_VALUE + 1L,
144                 Short.MIN_VALUE - 1L, Short.MIN_VALUE, Short.MIN_VALUE + 1L, };
145         return LongStream.concat(LongStream.range(-256L, 256L), Arrays.stream(l))
146                 .mapToObj(v -> new Object[] { v }).toArray(Object[][]::new);
147     }
148 
149     @Test(dataProvider = "unsignedLongToIntData")
150     public void testUnsignedLongToInt(long longValue) {
151         int intValue = (int) (longValue & 0xFFFF_FFFFL);
152 
153         MemoryLayout layout = MemoryLayouts.BITS_32_BE;
154         VarHandle intHandle = layout.varHandle(int.class);
155         VarHandle longHandle = MemoryHandles.asUnsigned(intHandle, long.class);
156 
157         try (ResourceScope scope = ResourceScope.newConfinedScope()) {
158             MemorySegment segment = MemorySegment.allocateNative(layout, scope);
159             longHandle.set(segment, longValue);
160             long expectedLongValue = Integer.toUnsignedLong(intValue);
161             assertEquals((long) longHandle.get(segment), expectedLongValue);
162             assertEquals((int) intHandle.get(segment), intValue);
163         }
164     }
165 
166     @Test
167     public void testCoordinatesSequenceLayout() {
168         MemoryLayout layout = MemoryLayout.sequenceLayout(2, MemoryLayouts.BITS_8_BE);
169         VarHandle byteHandle = layout.varHandle(byte.class, PathElement.sequenceElement());
170         VarHandle intHandle = MemoryHandles.asUnsigned(byteHandle, int.class);
171 
172         try (ResourceScope scope = ResourceScope.newConfinedScope()) {
173             MemorySegment segment = MemorySegment.allocateNative(layout, scope);
174             intHandle.set(segment, 0L, (int) -1);
175             assertEquals((int) intHandle.get(segment, 0L), 255);
176             intHandle.set(segment, 1L, (int) 200);
177             assertEquals((int) intHandle.get(segment, 1L), 200);
178         }
179     }
180 
181     @Test
182     public void testCoordinatesStride() {
183         byte[] arr = { 0, 0, (byte) 129, 0 };
184         MemorySegment segment = MemorySegment.ofArray(arr);
185 
186         {
187             VarHandle byteHandle = MemoryLayout.sequenceLayout(MemoryLayouts.JAVA_BYTE)
188                     .varHandle(byte.class, PathElement.sequenceElement());
189             VarHandle intHandle = MemoryHandles.asUnsigned(byteHandle, int.class);
190             assertEquals((int) intHandle.get(segment, 2L), 129);
191         }
192         {
193             VarHandle byteHandle = MemoryLayout.sequenceLayout(MemoryLayouts.JAVA_BYTE)
194                     .varHandle(byte.class, PathElement.sequenceElement());
195             VarHandle intHandle = MemoryHandles.asUnsigned(byteHandle, int.class);
196             assertEquals((int) intHandle.get(segment, 2L), 129);
197         }
198     }
199 
200     static final Class<NullPointerException> NPE = NullPointerException.class;
201 
202     @Test
203     public void testNull() {
204         VarHandle handle = MemoryHandles.varHandle(byte.class, BIG_ENDIAN);
205         assertThrows(NPE, () -> MemoryHandles.asUnsigned(handle, null));
206         assertThrows(NPE, () -> MemoryHandles.asUnsigned(null, short.class));
207         assertThrows(NPE, () -> MemoryHandles.asUnsigned(null, null));
208     }
209 
210     static final Class<IllegalArgumentException> IAE = IllegalArgumentException.class;
211 
212     static void assertIllegalArgumentExceptionIllegalCarrier(Class<?> carrier, Class<?> adaptedType) {
213         var vh = MemoryHandles.varHandle(carrier, BIG_ENDIAN);
214         var exception = expectThrows(IAE, () -> MemoryHandles.asUnsigned(vh, adaptedType));
215         var msg = exception.getMessage();
216         assertTrue(msg.contains("illegal carrier"), "Expected \"illegal carrier\" in:[" + msg +"]");
217     }
218 
219     static void assertIllegalArgumentExceptionIllegalAdapter(Class<?> carrier, Class<?> adaptedType) {
220         var vh = MemoryHandles.varHandle(carrier, BIG_ENDIAN);
221         var exception = expectThrows(IAE, () -> MemoryHandles.asUnsigned(vh, adaptedType));
222         var msg = exception.getMessage();
223         assertTrue(msg.contains("illegal adapter type"), "Expected \"illegal adapter type\" in:[" + msg +"]");
224     }
225 
226     static void assertIllegalArgumentExceptionIsNotWiderThan(Class<?> carrier, Class<?> adaptedType) {
227         var vh = MemoryHandles.varHandle(carrier, BIG_ENDIAN);
228         var exception = expectThrows(IAE, () -> MemoryHandles.asUnsigned(vh, adaptedType));
229         var msg = exception.getMessage();
230         assertTrue(msg.contains("is not wider than"), "Expected \"is not wider than\" in:[" + msg +"]");
231     }
232 
233     @Test
234     public void testIllegalArgumentException() {
235         assertIllegalArgumentExceptionIllegalCarrier(char.class,   long.class);
236         assertIllegalArgumentExceptionIllegalCarrier(double.class, long.class);
237         assertIllegalArgumentExceptionIllegalCarrier(float.class,  long.class);
238         assertIllegalArgumentExceptionIllegalCarrier(long.class,   long.class);
239 
240         assertIllegalArgumentExceptionIllegalAdapter(byte.class, void.class);
241         assertIllegalArgumentExceptionIllegalAdapter(byte.class, byte.class);
242         assertIllegalArgumentExceptionIllegalAdapter(byte.class, short.class);
243         assertIllegalArgumentExceptionIllegalAdapter(byte.class, char.class);
244         assertIllegalArgumentExceptionIllegalAdapter(byte.class, double.class);
245         assertIllegalArgumentExceptionIllegalAdapter(byte.class, float.class);
246         assertIllegalArgumentExceptionIllegalAdapter(byte.class, Object.class);
247         assertIllegalArgumentExceptionIllegalAdapter(byte.class, Integer.class);
248         assertIllegalArgumentExceptionIllegalAdapter(byte.class, Long.class);
249         assertIllegalArgumentExceptionIllegalAdapter(byte.class, long[].class);
250         assertIllegalArgumentExceptionIllegalAdapter(byte.class, int[].class);
251         assertIllegalArgumentExceptionIllegalAdapter(byte.class, Integer[].class);
252         assertIllegalArgumentExceptionIllegalAdapter(byte.class, Long[].class);
253 
254         assertIllegalArgumentExceptionIsNotWiderThan(int.class, int.class);
255     }
256 }

  8  *
  9  *  This code is distributed in the hope that it will be useful, but WITHOUT
 10  *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  *  version 2 for more details (a copy is included in the LICENSE file that
 13  *  accompanied this code).
 14  *
 15  *  You should have received a copy of the GNU General Public License version
 16  *  2 along with this work; if not, write to the Free Software Foundation,
 17  *  Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  *   Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  *  or visit www.oracle.com if you need additional information or have any
 21  *  questions.
 22  *
 23  */
 24 
 25 import jdk.incubator.foreign.MemoryHandles;
 26 import jdk.incubator.foreign.MemoryLayout;
 27 import jdk.incubator.foreign.MemoryLayout.PathElement;

 28 import jdk.incubator.foreign.MemorySegment;
 29 import java.lang.invoke.VarHandle;
 30 import java.nio.ByteOrder;
 31 import java.util.Arrays;
 32 import java.util.stream.IntStream;
 33 import java.util.stream.LongStream;
 34 
 35 import jdk.incubator.foreign.ResourceScope;
 36 import jdk.incubator.foreign.ValueLayout;
 37 import org.testng.annotations.*;
 38 import static java.nio.ByteOrder.BIG_ENDIAN;
 39 import static org.testng.Assert.*;
 40 
 41 /*
 42  * @test
 43  * @run testng TestMemoryHandleAsUnsigned
 44  */
 45 
 46 public class TestMemoryHandleAsUnsigned {
 47 
 48     @DataProvider(name = "unsignedIntToByteData")
 49     public Object[][] unsignedIntToByteData() {
 50         return IntStream.range(0, 256)
 51                 .mapToObj(v -> new Object[] { v }).toArray(Object[][]::new);
 52     }
 53 
 54     @Test(dataProvider = "unsignedIntToByteData")
 55     public void testUnsignedIntToByte(int intValue) {
 56         byte byteValue = (byte) (intValue & 0xFF);
 57 
 58         MemoryLayout layout = ValueLayout.JAVA_BYTE;
 59         VarHandle byteHandle = layout.varHandle();
 60         VarHandle intHandle = MemoryHandles.asUnsigned(byteHandle, int.class);
 61 
 62         try (ResourceScope scope = ResourceScope.newConfinedScope()) {
 63             MemorySegment segment = MemorySegment.allocateNative(layout, scope);
 64             intHandle.set(segment, intValue);
 65             int expectedIntValue = Byte.toUnsignedInt(byteValue);
 66             assertEquals((int) intHandle.get(segment), expectedIntValue);
 67             assertEquals((byte) byteHandle.get(segment), byteValue);
 68         }
 69     }
 70 
 71     @DataProvider(name = "unsignedLongToByteData")
 72     public Object[][] unsignedLongToByteData() {
 73         return LongStream.range(0L, 256L)
 74                 .mapToObj(v -> new Object[] { v }).toArray(Object[][]::new);
 75     }
 76 
 77     @Test(dataProvider = "unsignedLongToByteData")
 78     public void testUnsignedLongToByte(long longValue) {
 79         byte byteValue = (byte) (longValue & 0xFFL);
 80 
 81         MemoryLayout layout = ValueLayout.JAVA_BYTE;
 82         VarHandle byteHandle = layout.varHandle();
 83         VarHandle longHandle = MemoryHandles.asUnsigned(byteHandle, long.class);
 84 
 85         try (ResourceScope scope = ResourceScope.newConfinedScope()) {
 86             MemorySegment segment = MemorySegment.allocateNative(layout, scope);
 87             longHandle.set(segment, longValue);
 88             long expectedLongValue = Byte.toUnsignedLong(byteValue);
 89             assertEquals((long) longHandle.get(segment), expectedLongValue);
 90             assertEquals((byte) byteHandle.get(segment), byteValue);
 91         }
 92     }
 93 
 94     @DataProvider(name = "unsignedIntToShortData")
 95     public Object[][] unsignedIntToShortData() {
 96         return IntStream.range(0, 65_536).filter(i -> i % 99 == 0)
 97                 .mapToObj(v -> new Object[] { v }).toArray(Object[][]::new);
 98     }
 99 
100     @Test(dataProvider = "unsignedIntToShortData")
101     public void testUnsignedIntToShort(int intValue) {
102         short shortValue = (short) (intValue & 0xFFFF);
103 
104         MemoryLayout layout = ValueLayout.JAVA_SHORT.withOrder(ByteOrder.BIG_ENDIAN);
105         VarHandle shortHandle = layout.varHandle();
106         VarHandle intHandle = MemoryHandles.asUnsigned(shortHandle, int.class);
107 
108         try (ResourceScope scope = ResourceScope.newConfinedScope()) {
109             MemorySegment segment = MemorySegment.allocateNative(layout, scope);
110             intHandle.set(segment, intValue);
111             int expectedIntValue = Short.toUnsignedInt(shortValue);
112             assertEquals((int) intHandle.get(segment), expectedIntValue);
113             assertEquals((short) shortHandle.get(segment), shortValue);
114         }
115     }
116 
117     @DataProvider(name = "unsignedLongToShortData")
118     public Object[][] unsignedLongToShortData() {
119         return LongStream.range(0L, 65_536L).filter(i -> i % 99 == 0)
120                 .mapToObj(v -> new Object[] { v }).toArray(Object[][]::new);
121     }
122 
123     @Test(dataProvider = "unsignedLongToShortData")
124     public void testUnsignedLongToShort(long longValue) {
125         short shortValue = (short) (longValue & 0xFFFFL);
126 
127         MemoryLayout layout = ValueLayout.JAVA_SHORT.withOrder(ByteOrder.BIG_ENDIAN);
128         VarHandle shortHandle = layout.varHandle();
129         VarHandle longHandle = MemoryHandles.asUnsigned(shortHandle, long.class);
130 
131         try (ResourceScope scope = ResourceScope.newConfinedScope()) {
132             MemorySegment segment = MemorySegment.allocateNative(layout, scope);
133             longHandle.set(segment, longValue);
134             long expectedLongValue = Short.toUnsignedLong(shortValue);
135             assertEquals((long) longHandle.get(segment), expectedLongValue);
136             assertEquals((short) shortHandle.get(segment), shortValue);
137         }
138     }
139 
140     @DataProvider(name = "unsignedLongToIntData")
141     public Object[][] unsignedLongToIntData() {
142         // some boundary values
143         long[] l = new long[] { Long.MAX_VALUE, Long.MIN_VALUE,
144                 Short.MAX_VALUE - 1L, Short.MAX_VALUE, Short.MAX_VALUE + 1L,
145                 Short.MIN_VALUE - 1L, Short.MIN_VALUE, Short.MIN_VALUE + 1L, };
146         return LongStream.concat(LongStream.range(-256L, 256L), Arrays.stream(l))
147                 .mapToObj(v -> new Object[] { v }).toArray(Object[][]::new);
148     }
149 
150     @Test(dataProvider = "unsignedLongToIntData")
151     public void testUnsignedLongToInt(long longValue) {
152         int intValue = (int) (longValue & 0xFFFF_FFFFL);
153 
154         MemoryLayout layout = ValueLayout.JAVA_INT.withOrder(ByteOrder.BIG_ENDIAN);
155         VarHandle intHandle = layout.varHandle();
156         VarHandle longHandle = MemoryHandles.asUnsigned(intHandle, long.class);
157 
158         try (ResourceScope scope = ResourceScope.newConfinedScope()) {
159             MemorySegment segment = MemorySegment.allocateNative(layout, scope);
160             longHandle.set(segment, longValue);
161             long expectedLongValue = Integer.toUnsignedLong(intValue);
162             assertEquals((long) longHandle.get(segment), expectedLongValue);
163             assertEquals((int) intHandle.get(segment), intValue);
164         }
165     }
166 
167     @Test
168     public void testCoordinatesSequenceLayout() {
169         MemoryLayout layout = MemoryLayout.sequenceLayout(2, ValueLayout.JAVA_BYTE);
170         VarHandle byteHandle = layout.varHandle(PathElement.sequenceElement());
171         VarHandle intHandle = MemoryHandles.asUnsigned(byteHandle, int.class);
172 
173         try (ResourceScope scope = ResourceScope.newConfinedScope()) {
174             MemorySegment segment = MemorySegment.allocateNative(layout, scope);
175             intHandle.set(segment, 0L, (int) -1);
176             assertEquals((int) intHandle.get(segment, 0L), 255);
177             intHandle.set(segment, 1L, (int) 200);
178             assertEquals((int) intHandle.get(segment, 1L), 200);
179         }
180     }
181 
182     @Test
183     public void testCoordinatesStride() {
184         byte[] arr = { 0, 0, (byte) 129, 0 };
185         MemorySegment segment = MemorySegment.ofArray(arr);
186 
187         {
188             VarHandle byteHandle = MemoryLayout.sequenceLayout(ValueLayout.JAVA_BYTE)
189                     .varHandle(PathElement.sequenceElement());
190             VarHandle intHandle = MemoryHandles.asUnsigned(byteHandle, int.class);
191             assertEquals((int) intHandle.get(segment, 2L), 129);
192         }
193         {
194             VarHandle byteHandle = MemoryLayout.sequenceLayout(ValueLayout.JAVA_BYTE)
195                     .varHandle(PathElement.sequenceElement());
196             VarHandle intHandle = MemoryHandles.asUnsigned(byteHandle, int.class);
197             assertEquals((int) intHandle.get(segment, 2L), 129);
198         }
199     }
200 
201     static final Class<NullPointerException> NPE = NullPointerException.class;
202 
203     @Test
204     public void testNull() {
205         VarHandle handle = MemoryHandles.varHandle(ValueLayout.JAVA_BYTE.withOrder(BIG_ENDIAN));
206         assertThrows(NPE, () -> MemoryHandles.asUnsigned(handle, null));
207         assertThrows(NPE, () -> MemoryHandles.asUnsigned(null, short.class));
208         assertThrows(NPE, () -> MemoryHandles.asUnsigned(null, null));
209     }
210 
211     static final Class<IllegalArgumentException> IAE = IllegalArgumentException.class;
212 
213     static void assertIllegalArgumentExceptionIllegalCarrier(ValueLayout layout, Class<?> adaptedType) {
214         var vh = MemoryHandles.varHandle(layout.withOrder(BIG_ENDIAN));
215         var exception = expectThrows(IAE, () -> MemoryHandles.asUnsigned(vh, adaptedType));
216         var msg = exception.getMessage();
217         assertTrue(msg.contains("illegal carrier"), "Expected \"illegal carrier\" in:[" + msg +"]");
218     }
219 
220     static void assertIllegalArgumentExceptionIllegalAdapter(ValueLayout layout, Class<?> adaptedType) {
221         var vh = MemoryHandles.varHandle(layout.withOrder(BIG_ENDIAN));
222         var exception = expectThrows(IAE, () -> MemoryHandles.asUnsigned(vh, adaptedType));
223         var msg = exception.getMessage();
224         assertTrue(msg.contains("illegal adapter type"), "Expected \"illegal adapter type\" in:[" + msg +"]");
225     }
226 
227     static void assertIllegalArgumentExceptionIsNotWiderThan(ValueLayout layout, Class<?> adaptedType) {
228         var vh = MemoryHandles.varHandle(layout.withOrder(BIG_ENDIAN));
229         var exception = expectThrows(IAE, () -> MemoryHandles.asUnsigned(vh, adaptedType));
230         var msg = exception.getMessage();
231         assertTrue(msg.contains("is not wider than"), "Expected \"is not wider than\" in:[" + msg +"]");
232     }
233 
234     @Test
235     public void testIllegalArgumentException() {
236         assertIllegalArgumentExceptionIllegalCarrier(ValueLayout.JAVA_CHAR,   long.class);
237         assertIllegalArgumentExceptionIllegalCarrier(ValueLayout.JAVA_DOUBLE, long.class);
238         assertIllegalArgumentExceptionIllegalCarrier(ValueLayout.JAVA_FLOAT,  long.class);
239         assertIllegalArgumentExceptionIllegalCarrier(ValueLayout.JAVA_LONG,   long.class);
240 
241         assertIllegalArgumentExceptionIllegalAdapter(ValueLayout.JAVA_BYTE, void.class);
242         assertIllegalArgumentExceptionIllegalAdapter(ValueLayout.JAVA_BYTE, byte.class);
243         assertIllegalArgumentExceptionIllegalAdapter(ValueLayout.JAVA_BYTE, short.class);
244         assertIllegalArgumentExceptionIllegalAdapter(ValueLayout.JAVA_BYTE, char.class);
245         assertIllegalArgumentExceptionIllegalAdapter(ValueLayout.JAVA_BYTE, double.class);
246         assertIllegalArgumentExceptionIllegalAdapter(ValueLayout.JAVA_BYTE, float.class);
247         assertIllegalArgumentExceptionIllegalAdapter(ValueLayout.JAVA_BYTE, Object.class);
248         assertIllegalArgumentExceptionIllegalAdapter(ValueLayout.JAVA_BYTE, Integer.class);
249         assertIllegalArgumentExceptionIllegalAdapter(ValueLayout.JAVA_BYTE, Long.class);
250         assertIllegalArgumentExceptionIllegalAdapter(ValueLayout.JAVA_BYTE, long[].class);
251         assertIllegalArgumentExceptionIllegalAdapter(ValueLayout.JAVA_BYTE, int[].class);
252         assertIllegalArgumentExceptionIllegalAdapter(ValueLayout.JAVA_BYTE, Integer[].class);
253         assertIllegalArgumentExceptionIllegalAdapter(ValueLayout.JAVA_BYTE, Long[].class);
254 
255         assertIllegalArgumentExceptionIsNotWiderThan(ValueLayout.JAVA_INT, int.class);
256     }
257 }
< prev index next >