use of jdk.incubator.foreign.MemoryAddress in project openj9 by eclipse.
the class PrimitiveTypeTests method test_addTwoInts_fromMemAddr.
@Test
public void test_addTwoInts_fromMemAddr() throws Throwable {
MethodType mt = MethodType.methodType(int.class, int.class, int.class);
FunctionDescriptor fd = FunctionDescriptor.of(C_INT, C_INT, C_INT);
Symbol functionSymbol = nativeLib.lookup("add2Ints").get();
MemoryAddress memAddr = functionSymbol.address();
MethodHandle mh = clinker.downcallHandle(memAddr, mt, fd);
int result = (int) mh.invokeExact(112, 123);
Assert.assertEquals(result, 235);
FunctionDescriptor fd2 = FunctionDescriptor.of(C_INT.withName("int"), C_INT.withName("int"), C_INT.withName("int"));
mh = clinker.downcallHandle(memAddr, mt, fd2);
result = (int) mh.invokeExact(234, 567);
Assert.assertEquals(result, 801);
}
use of jdk.incubator.foreign.MemoryAddress in project openj9 by eclipse.
the class PrimitiveTypeTests method test_addTwoBytes_fromMemAddr.
@Test
public void test_addTwoBytes_fromMemAddr() throws Throwable {
MethodType mt = MethodType.methodType(byte.class, byte.class, byte.class);
FunctionDescriptor fd = FunctionDescriptor.of(C_CHAR, C_CHAR, C_CHAR);
Symbol functionSymbol = nativeLib.lookup("add2Bytes").get();
MemoryAddress memAddr = functionSymbol.address();
MethodHandle mh = clinker.downcallHandle(memAddr, mt, fd);
byte result = (byte) mh.invokeExact((byte) 6, (byte) 3);
Assert.assertEquals(result, (byte) 9);
FunctionDescriptor fd2 = FunctionDescriptor.of(C_CHAR.withName("char"), C_CHAR.withName("char"), C_CHAR.withName("char"));
mh = clinker.downcallHandle(memAddr, mt, fd2);
result = (byte) mh.invokeExact((byte) 6, (byte) 7);
Assert.assertEquals(result, (byte) 13);
}
use of jdk.incubator.foreign.MemoryAddress in project openj9 by eclipse.
the class PrimitiveTypeTests method test_addTwoDoubles_fromMemAddr.
@Test
public void test_addTwoDoubles_fromMemAddr() throws Throwable {
MethodType mt = MethodType.methodType(double.class, double.class, double.class);
FunctionDescriptor fd = FunctionDescriptor.of(C_DOUBLE, C_DOUBLE, C_DOUBLE);
Symbol functionSymbol = nativeLib.lookup("add2Doubles").get();
MemoryAddress memAddr = functionSymbol.address();
MethodHandle mh = clinker.downcallHandle(memAddr, mt, fd);
double result = (double) mh.invokeExact(159.748d, 262.795d);
Assert.assertEquals(result, 422.543d, 0.001d);
FunctionDescriptor fd2 = FunctionDescriptor.of(C_DOUBLE.withName("double"), C_DOUBLE.withName("double"), C_DOUBLE.withName("double"));
mh = clinker.downcallHandle(memAddr, mt, fd2);
result = (double) mh.invokeExact(1159.748d, 1262.795d);
Assert.assertEquals(result, 2422.543d, 0.001d);
}
use of jdk.incubator.foreign.MemoryAddress in project openj9 by eclipse.
the class PrimitiveTypeTests method test_addTwoBoolsWithOr_fromMemAddr.
@Test
public void test_addTwoBoolsWithOr_fromMemAddr() throws Throwable {
MethodType mt = MethodType.methodType(boolean.class, boolean.class, boolean.class);
FunctionDescriptor fd = FunctionDescriptor.of(C_INT, C_INT, C_INT);
Symbol functionSymbol = nativeLib.lookup("add2BoolsWithOr").get();
MemoryAddress memAddr = functionSymbol.address();
MethodHandle mh = clinker.downcallHandle(memAddr, mt, fd);
boolean result = (boolean) mh.invokeExact(true, false);
Assert.assertEquals(result, true);
FunctionDescriptor fd2 = FunctionDescriptor.of(C_INT.withName("int"), C_INT.withName("int"), C_INT.withName("int"));
mh = clinker.downcallHandle(functionSymbol, mt, fd2);
result = (boolean) mh.invokeExact(false, true);
Assert.assertEquals(result, true);
}
use of jdk.incubator.foreign.MemoryAddress in project openj9 by eclipse.
the class PrimitiveTypeTests method test_addTwoShorts_fromMemAddr.
@Test
public void test_addTwoShorts_fromMemAddr() throws Throwable {
MethodType mt = MethodType.methodType(short.class, short.class, short.class);
FunctionDescriptor fd = FunctionDescriptor.of(C_SHORT, C_SHORT, C_SHORT);
Symbol functionSymbol = nativeLib.lookup("add2Shorts").get();
MemoryAddress memAddr = functionSymbol.address();
MethodHandle mh = clinker.downcallHandle(memAddr, mt, fd);
short result = (short) mh.invokeExact((short) 24, (short) 32);
Assert.assertEquals(result, (short) 56);
FunctionDescriptor fd2 = FunctionDescriptor.of(C_SHORT.withName("short"), C_SHORT.withName("short"), C_SHORT.withName("short"));
mh = clinker.downcallHandle(memAddr, mt, fd2);
result = (short) mh.invokeExact((short) 12, (short) 34);
Assert.assertEquals(result, (short) 46);
}
Aggregations