use of jdk.incubator.foreign.LibraryLookup.Symbol in project openj9 by eclipse.
the class PrimitiveTypeTests method test_generateNewChar_fromMemAddr.
@Test
public void test_generateNewChar_fromMemAddr() throws Throwable {
MethodType mt = MethodType.methodType(char.class, char.class, char.class);
FunctionDescriptor fd = FunctionDescriptor.of(C_SHORT, C_SHORT, C_SHORT);
Symbol functionSymbol = nativeLib.lookup("createNewCharFrom2Chars").get();
MemoryAddress memAddr = functionSymbol.address();
MethodHandle mh = clinker.downcallHandle(memAddr, mt, fd);
char result = (char) mh.invokeExact('B', 'D');
Assert.assertEquals(result, 'C');
FunctionDescriptor fd2 = FunctionDescriptor.of(C_SHORT.withName("short"), C_SHORT.withName("short"), C_SHORT.withName("short"));
mh = clinker.downcallHandle(memAddr, mt, fd2);
result = (char) mh.invokeExact('B', 'D');
Assert.assertEquals(result, 'C');
}
use of jdk.incubator.foreign.LibraryLookup.Symbol in project openj9 by eclipse.
the class PrimitiveTypeTests method test_addTwoNegtiveBytes.
@Test
public void test_addTwoNegtiveBytes() 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();
MethodHandle mh = clinker.downcallHandle(functionSymbol, 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(functionSymbol, mt, fd2);
result = (byte) mh.invokeExact((byte) -7, (byte) -8);
Assert.assertEquals(result, (byte) -15);
}
use of jdk.incubator.foreign.LibraryLookup.Symbol in project openj9 by eclipse.
the class PrimitiveTypeTests method test_addShortAndShortFromPointer.
@Test
public void test_addShortAndShortFromPointer() throws Throwable {
MethodType mt = MethodType.methodType(short.class, MemoryAddress.class, short.class);
FunctionDescriptor fd = FunctionDescriptor.of(C_SHORT, C_POINTER, C_SHORT);
Symbol functionSymbol = nativeLib.lookup("addShortAndShortFromPointer").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, mt, fd);
MemorySegment shortSegmt = MemorySegment.allocateNative(C_SHORT);
MemoryAccess.setShort(shortSegmt, (short) 24);
short result = (short) mh.invokeExact(shortSegmt.address(), (short) 32);
Assert.assertEquals(result, (short) 56);
FunctionDescriptor fd2 = FunctionDescriptor.of(C_SHORT.withName("short"), C_POINTER.withName("pointer"), C_SHORT.withName("short"));
mh = clinker.downcallHandle(functionSymbol, mt, fd2);
shortSegmt = MemorySegment.allocateNative(C_SHORT);
MemoryAccess.setShort(shortSegmt, (short) 22);
result = (short) mh.invokeExact(shortSegmt.address(), (short) 33);
Assert.assertEquals(result, (short) 55);
}
use of jdk.incubator.foreign.LibraryLookup.Symbol in project openj9 by eclipse.
the class PrimitiveTypeTests method test_addIntAndChar_fromMemAddr.
@Test
public void test_addIntAndChar_fromMemAddr() throws Throwable {
MethodType mt = MethodType.methodType(int.class, int.class, char.class);
FunctionDescriptor fd = FunctionDescriptor.of(C_INT, C_INT, C_SHORT);
Symbol functionSymbol = nativeLib.lookup("addIntAndChar").get();
MemoryAddress memAddr = functionSymbol.address();
MethodHandle mh = clinker.downcallHandle(memAddr, mt, fd);
int result = (int) mh.invokeExact(58, 'A');
Assert.assertEquals(result, 123);
FunctionDescriptor fd2 = FunctionDescriptor.of(C_INT.withName("int"), C_INT.withName("int"), C_SHORT.withName("short"));
mh = clinker.downcallHandle(memAddr, mt, fd2);
result = (int) mh.invokeExact(60, 'B');
Assert.assertEquals(result, 126);
}
use of jdk.incubator.foreign.LibraryLookup.Symbol in project openj9 by eclipse.
the class PrimitiveTypeTests method test_addTwoFloats_fromMemAddr.
@Test
public void test_addTwoFloats_fromMemAddr() throws Throwable {
MethodType mt = MethodType.methodType(float.class, float.class, float.class);
FunctionDescriptor fd = FunctionDescriptor.of(C_FLOAT, C_FLOAT, C_FLOAT);
Symbol functionSymbol = nativeLib.lookup("add2Floats").get();
MemoryAddress memAddr = functionSymbol.address();
MethodHandle mh = clinker.downcallHandle(memAddr, mt, fd);
float result = (float) mh.invokeExact(5.74f, 6.79f);
Assert.assertEquals(result, 12.53f, 0.01f);
FunctionDescriptor fd2 = FunctionDescriptor.of(C_FLOAT.withName("float"), C_FLOAT.withName("float"), C_FLOAT.withName("float"));
mh = clinker.downcallHandle(memAddr, mt, fd2);
result = (float) mh.invokeExact(15.74f, 16.79f);
Assert.assertEquals(result, 32.53f, 0.01f);
}
Aggregations