use of jdk.incubator.foreign.FunctionDescriptor in project openj9 by eclipse.
the class PrimitiveTypeTests2 method test_addTwoFloats_2.
@Test
public void test_addTwoFloats_2() throws Throwable {
MethodType mt = MethodType.methodType(float.class, float.class, float.class);
FunctionDescriptor fd = FunctionDescriptor.of(C_FLOAT, C_FLOAT, C_FLOAT);
Addressable functionSymbol = nativeLibLookup.lookup("add2Floats").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, allocator, mt, fd);
float result = (float) mh.invokeExact(5.74f, 6.79f);
Assert.assertEquals(result, 12.53f, 0.01f);
}
use of jdk.incubator.foreign.FunctionDescriptor in project openj9 by eclipse.
the class PrimitiveTypeTests2 method test_generateNewChar_fromMemAddr_2.
@Test
public void test_generateNewChar_fromMemAddr_2() throws Throwable {
MethodType mt = MethodType.methodType(char.class, char.class, char.class);
FunctionDescriptor fd = FunctionDescriptor.of(C_SHORT, C_SHORT, C_SHORT);
Addressable functionSymbol = nativeLibLookup.lookup("createNewCharFrom2Chars").get();
MemoryAddress memAddr = functionSymbol.address();
MethodHandle mh = clinker.downcallHandle(memAddr, allocator, mt, fd);
char result = (char) mh.invokeExact('B', 'D');
Assert.assertEquals(result, 'C');
}
use of jdk.incubator.foreign.FunctionDescriptor in project openj9 by eclipse.
the class PrimitiveTypeTests2 method test_addTwoFloats_fromMemAddr_2.
@Test
public void test_addTwoFloats_fromMemAddr_2() throws Throwable {
MethodType mt = MethodType.methodType(float.class, float.class, float.class);
FunctionDescriptor fd = FunctionDescriptor.of(C_FLOAT, C_FLOAT, C_FLOAT);
Addressable functionSymbol = nativeLibLookup.lookup("add2Floats").get();
MemoryAddress memAddr = functionSymbol.address();
MethodHandle mh = clinker.downcallHandle(memAddr, allocator, mt, fd);
float result = (float) mh.invokeExact(5.74f, 6.79f);
Assert.assertEquals(result, 12.53f, 0.01f);
}
use of jdk.incubator.foreign.FunctionDescriptor in project openj9 by eclipse.
the class PrimitiveTypeTests2 method test_addTwoLongs_2.
@Test
public void test_addTwoLongs_2() throws Throwable {
MethodType mt = MethodType.methodType(long.class, long.class, long.class);
FunctionDescriptor fd = FunctionDescriptor.of(longLayout, longLayout, longLayout);
Addressable functionSymbol = nativeLibLookup.lookup("add2Longs").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, allocator, mt, fd);
long result = (long) mh.invokeExact(57424L, 698235L);
Assert.assertEquals(result, 755659L);
}
use of jdk.incubator.foreign.FunctionDescriptor in project openj9 by eclipse.
the class PrimitiveTypeTests2 method test_addTwoIntsReturnVoid_2.
@Test
public void test_addTwoIntsReturnVoid_2() throws Throwable {
MethodType mt = MethodType.methodType(void.class, int.class, int.class);
FunctionDescriptor fd = FunctionDescriptor.ofVoid(C_INT, C_INT);
Addressable functionSymbol = nativeLibLookup.lookup("add2IntsReturnVoid").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, allocator, mt, fd);
mh.invokeExact(454, 398);
}
Aggregations