use of jdk.incubator.foreign.FunctionDescriptor in project openj9 by eclipse.
the class PrimitiveTypeTests2 method test_addTwoBytes_2.
@Test
public void test_addTwoBytes_2() throws Throwable {
MethodType mt = MethodType.methodType(byte.class, byte.class, byte.class);
FunctionDescriptor fd = FunctionDescriptor.of(C_CHAR, C_CHAR, C_CHAR);
Addressable functionSymbol = nativeLibLookup.lookup("add2Bytes").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, allocator, mt, fd);
byte result = (byte) mh.invokeExact((byte) 6, (byte) 3);
Assert.assertEquals(result, (byte) 9);
}
use of jdk.incubator.foreign.FunctionDescriptor in project openj9 by eclipse.
the class PrimitiveTypeTests2 method test_addIntAndChar_2.
@Test
public void test_addIntAndChar_2() throws Throwable {
MethodType mt = MethodType.methodType(int.class, int.class, char.class);
FunctionDescriptor fd = FunctionDescriptor.of(C_INT, C_INT, C_SHORT);
Addressable functionSymbol = nativeLibLookup.lookup("addIntAndChar").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, allocator, mt, fd);
int result = (int) mh.invokeExact(58, 'A');
Assert.assertEquals(result, 123);
}
use of jdk.incubator.foreign.FunctionDescriptor in project openj9 by eclipse.
the class PrimitiveTypeTests2 method test_generateNewChar_2.
@Test
public void test_generateNewChar_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();
MethodHandle mh = clinker.downcallHandle(functionSymbol, 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_addBoolAndBoolFromPointerWithOr_2.
@Test
public void test_addBoolAndBoolFromPointerWithOr_2() throws Throwable {
MethodType mt = MethodType.methodType(boolean.class, boolean.class, MemoryAddress.class);
FunctionDescriptor fd = FunctionDescriptor.of(C_CHAR, C_CHAR, C_POINTER);
Addressable functionSymbol = nativeLibLookup.lookup("addBoolAndBoolFromPointerWithOr").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, allocator, mt, fd);
MemorySegment boolSegmt = MemorySegment.allocateNative(C_CHAR, resourceScope);
MemoryAccess.setByte(boolSegmt, (byte) 1);
boolean result = (boolean) mh.invokeExact(false, boolSegmt.address());
Assert.assertEquals(result, true);
}
use of jdk.incubator.foreign.FunctionDescriptor in project openj9 by eclipse.
the class PrimitiveTypeTests2 method test_strlenFromDefaultLibWithMemAddr_fromMemAddr_2.
@Test
public void test_strlenFromDefaultLibWithMemAddr_fromMemAddr_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 strlenSymbol = defaultLibLookup.lookup("strlen").get();
MemoryAddress memAddr = strlenSymbol.address();
MethodType mt = MethodType.methodType(long.class, MemoryAddress.class);
FunctionDescriptor fd = FunctionDescriptor.of(longLayout, C_POINTER);
MethodHandle mh = clinker.downcallHandle(memAddr, allocator, mt, fd);
MemorySegment funcMemSegment = CLinker.toCString("JEP389 DOWNCALL TEST SUITES", resourceScope);
long strLength = (long) mh.invokeExact(funcMemSegment.address());
Assert.assertEquals(strLength, 27);
}
}
Aggregations