use of jdk.incubator.foreign.Addressable in project openj9 by eclipse.
the class InvalidDownCallTests method test_invalidByteTypeOnReturn.
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "The return type must be .*")
public void test_invalidByteTypeOnReturn() throws Throwable {
MethodType mt = MethodType.methodType(Byte.class, byte.class, byte.class);
FunctionDescriptor fd = FunctionDescriptor.of(C_CHAR, C_CHAR, C_CHAR);
Addressable functionSymbol = nativeLibLookup.lookup("add2Bytes").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, mt, fd);
fail("Failed to throw out IllegalArgumentException in the case of the Byte return type");
}
use of jdk.incubator.foreign.Addressable in project openj9 by eclipse.
the class InvalidDownCallTests method test_mismatchedArity.
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = ".* inconsistent with the arity .*")
public void test_mismatchedArity() throws Throwable {
MethodType mt = MethodType.methodType(int.class, int.class, int.class);
FunctionDescriptor fd = FunctionDescriptor.of(C_INT, C_INT, C_INT, C_INT);
Addressable functionSymbol = nativeLibLookup.lookup("add2Ints").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, mt, fd);
fail("Failed to throw out IllegalArgumentException in the case of the mismatched arity");
}
use of jdk.incubator.foreign.Addressable in project openj9 by eclipse.
the class PrimitiveTypeTests2 method test_addFloatAndFloatFromPointer_2.
@Test
public void test_addFloatAndFloatFromPointer_2() throws Throwable {
MethodType mt = MethodType.methodType(float.class, float.class, MemoryAddress.class);
FunctionDescriptor fd = FunctionDescriptor.of(C_FLOAT, C_FLOAT, C_POINTER);
Addressable functionSymbol = nativeLibLookup.lookup("addFloatAndFloatFromPointer").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, allocator, mt, fd);
MemorySegment floatSegmt = MemorySegment.allocateNative(C_FLOAT, resourceScope);
MemoryAccess.setFloat(floatSegmt, 6.79f);
float result = (float) mh.invokeExact(5.74f, floatSegmt.address());
Assert.assertEquals(result, 12.53f, 0.01f);
}
use of jdk.incubator.foreign.Addressable in project openj9 by eclipse.
the class StructTests1 method test_addByteAndBytesFromNestedStruct_1.
@Test
public void test_addByteAndBytesFromNestedStruct_1() throws Throwable {
GroupLayout nestedStructLayout = MemoryLayout.structLayout(C_CHAR.withName("elem1"), C_CHAR.withName("elem2"));
GroupLayout structLayout = MemoryLayout.structLayout(nestedStructLayout.withName("struct_elem1"), C_CHAR.withName("elem2"));
MethodType mt = MethodType.methodType(byte.class, byte.class, MemorySegment.class);
FunctionDescriptor fd = FunctionDescriptor.of(C_CHAR, C_CHAR, structLayout);
Addressable functionSymbol = nativeLibLookup.lookup("addByteAndBytesFromNestedStruct").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, mt, fd);
try (ResourceScope scope = ResourceScope.newConfinedScope()) {
SegmentAllocator allocator = SegmentAllocator.ofScope(scope);
MemorySegment structSegmt = allocator.allocate(structLayout);
MemoryAccess.setByteAtOffset(structSegmt, 0, (byte) 11);
MemoryAccess.setByteAtOffset(structSegmt, 1, (byte) 22);
MemoryAccess.setByteAtOffset(structSegmt, 2, (byte) 33);
byte result = (byte) mh.invokeExact((byte) 46, structSegmt);
Assert.assertEquals(result, 112);
}
}
use of jdk.incubator.foreign.Addressable in project openj9 by eclipse.
the class StructTests1 method test_addByteAndBytesFromStructWithNestedByteArray_1.
@Test
public void test_addByteAndBytesFromStructWithNestedByteArray_1() throws Throwable {
SequenceLayout byteArray = MemoryLayout.sequenceLayout(2, C_CHAR);
GroupLayout structLayout = MemoryLayout.structLayout(byteArray.withName("array_elem1"), C_CHAR.withName("elem2"), MemoryLayout.paddingLayout(C_CHAR.bitSize()));
MethodType mt = MethodType.methodType(byte.class, byte.class, MemorySegment.class);
FunctionDescriptor fd = FunctionDescriptor.of(C_CHAR, C_CHAR, structLayout);
Addressable functionSymbol = nativeLibLookup.lookup("addByteAndBytesFromStructWithNestedByteArray").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, mt, fd);
try (ResourceScope scope = ResourceScope.newConfinedScope()) {
SegmentAllocator allocator = SegmentAllocator.ofScope(scope);
MemorySegment structSegmt = allocator.allocate(structLayout);
MemoryAccess.setByteAtOffset(structSegmt, 0, (byte) 11);
MemoryAccess.setByteAtOffset(structSegmt, 1, (byte) 12);
MemoryAccess.setByteAtOffset(structSegmt, 2, (byte) 13);
byte result = (byte) mh.invokeExact((byte) 14, structSegmt);
Assert.assertEquals(result, 50);
}
}
Aggregations