use of jdk.incubator.foreign.Addressable 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.Addressable 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.Addressable 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);
}
use of jdk.incubator.foreign.Addressable in project openj9 by eclipse.
the class PrimitiveTypeTests2 method test_printfFromDefaultLibWithMemAddr_2.
@Test
public void test_printfFromDefaultLibWithMemAddr_2() throws Throwable {
/* Temporarily disable the default library loading on AIX till we figure out a way
* around to handle the case as the official implementation in OpenJDK17 doesn't
* help to load the static libray (libc.a).
*/
if (!isAixOS) {
Addressable functionSymbol = defaultLibLookup.lookup("printf").get();
MethodType mt = MethodType.methodType(int.class, MemoryAddress.class, int.class, int.class, int.class);
FunctionDescriptor fd = FunctionDescriptor.of(C_INT, C_POINTER, C_INT, C_INT, C_INT);
MethodHandle mh = clinker.downcallHandle(functionSymbol, allocator, mt, fd);
MemorySegment formatMemSegment = CLinker.toCString("\n%d + %d = %d\n", resourceScope);
mh.invoke(formatMemSegment.address(), 15, 27, 42);
}
}
use of jdk.incubator.foreign.Addressable in project openj9 by eclipse.
the class PrimitiveTypeTests2 method test_addTwoInts_2.
@Test
public void test_addTwoInts_2() throws Throwable {
MethodType mt = MethodType.methodType(int.class, int.class, int.class);
FunctionDescriptor fd = FunctionDescriptor.of(C_INT, C_INT, C_INT);
Addressable functionSymbol = nativeLibLookup.lookup("add2Ints").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, allocator, mt, fd);
int result = (int) mh.invokeExact(112, 123);
Assert.assertEquals(result, 235);
}
Aggregations