use of jdk.incubator.foreign.FunctionDescriptor in project openj9 by eclipse.
the class PrimitiveTypeTests method test_addLongAndLongFromPointer.
@Test
public void test_addLongAndLongFromPointer() throws Throwable {
MethodType mt = MethodType.methodType(long.class, MemoryAddress.class, long.class);
FunctionDescriptor fd = FunctionDescriptor.of(longLayout, C_POINTER, longLayout);
Symbol functionSymbol = nativeLib.lookup("addLongAndLongFromPointer").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, mt, fd);
MemorySegment longSegmt = MemorySegment.allocateNative(longLayout);
MemoryAccess.setLong(longSegmt, 57424L);
long result = (long) mh.invokeExact(longSegmt.address(), 698235L);
longSegmt.close();
Assert.assertEquals(result, 755659L);
FunctionDescriptor fd2 = FunctionDescriptor.of(longLayout.withName("long"), C_POINTER.withName("int"), longLayout.withName("long"));
mh = clinker.downcallHandle(functionSymbol, mt, fd2);
longSegmt = MemorySegment.allocateNative(longLayout.withName("long"));
MemoryAccess.setLong(longSegmt, 11111L);
result = (long) mh.invokeExact(longSegmt.address(), 22222L);
longSegmt.close();
Assert.assertEquals(result, 33333L);
}
use of jdk.incubator.foreign.FunctionDescriptor in project openj9 by eclipse.
the class InvalidDownCallTests method test_mismatchedBoolArgWithShortLayout.
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "Mismatched size .*")
public void test_mismatchedBoolArgWithShortLayout() throws Throwable {
MethodType mt = MethodType.methodType(boolean.class, boolean.class, boolean.class);
FunctionDescriptor fd = FunctionDescriptor.of(C_CHAR, C_SHORT, C_CHAR);
Addressable functionSymbol = nativeLibLookup.lookup("add2BoolsWithOr").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, mt, fd);
fail("Failed to throw out IllegalArgumentException in the case of the mismatched layout");
}
use of jdk.incubator.foreign.FunctionDescriptor in project openj9 by eclipse.
the class InvalidDownCallTests method test_mismatchedIntArgTypeWithLongLayout.
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "Mismatched size .*")
public void test_mismatchedIntArgTypeWithLongLayout() throws Throwable {
MethodType mt = MethodType.methodType(long.class, int.class, long.class);
FunctionDescriptor fd = FunctionDescriptor.of(longLayout, longLayout, longLayout);
Addressable functionSymbol = nativeLibLookup.lookup("add2Longs").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, mt, fd);
fail("Failed to throw out IllegalArgumentException in the case of the mismatched int type");
}
use of jdk.incubator.foreign.FunctionDescriptor in project openj9 by eclipse.
the class InvalidDownCallTests method test_invalidBooleanTypeOnReturn.
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "The return type must be .*")
public void test_invalidBooleanTypeOnReturn() throws Throwable {
MethodType mt = MethodType.methodType(Boolean.class, boolean.class, boolean.class);
FunctionDescriptor fd = FunctionDescriptor.of(C_CHAR, C_CHAR, C_CHAR);
Addressable functionSymbol = nativeLibLookup.lookup("add2BoolsWithOr").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, mt, fd);
fail("Failed to throw out IllegalArgumentException in the case of the Boolean return type");
}
use of jdk.incubator.foreign.FunctionDescriptor in project openj9 by eclipse.
the class InvalidDownCallTests method test_mismatchedCharArgWithCharLayout.
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "Mismatched size .*")
public void test_mismatchedCharArgWithCharLayout() throws Throwable {
MethodType mt = MethodType.methodType(char.class, char.class, char.class);
FunctionDescriptor fd = FunctionDescriptor.of(C_SHORT, C_CHAR, C_SHORT);
Addressable functionSymbol = nativeLibLookup.lookup("createNewCharFrom2Chars").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, mt, fd);
fail("Failed to throw out IllegalArgumentException in the case of the mismatched layout");
}
Aggregations