use of jdk.incubator.foreign.NativeSymbol in project openj9 by eclipse.
the class InvalidDownCallTests method test_invalidMemoryLayoutForMemoryAddress.
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "Unsupported layout.*")
public void test_invalidMemoryLayoutForMemoryAddress() 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) {
throw new IllegalArgumentException("Unsupported layout");
} else {
NativeSymbol functionSymbol = clinker.lookup("strlen").get();
FunctionDescriptor fd = FunctionDescriptor.of(JAVA_LONG, MemoryLayout.paddingLayout(64));
MethodHandle mh = clinker.downcallHandle(functionSymbol, fd);
fail("Failed to throw out IllegalArgumentException in the case of the invalid MemoryLayout");
}
}
use of jdk.incubator.foreign.NativeSymbol in project openj9 by eclipse.
the class PrimitiveTypeTests1 method test_addIntAndIntFromPointer_1.
@Test
public void test_addIntAndIntFromPointer_1() throws Throwable {
FunctionDescriptor fd = FunctionDescriptor.of(JAVA_INT, JAVA_INT, ADDRESS);
NativeSymbol functionSymbol = nativeLibLookup.lookup("addIntAndIntFromPointer").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, fd);
MemorySegment intSegmt = nativeAllocator.allocate(JAVA_INT, 215);
int result = (int) mh.invoke(321, intSegmt);
Assert.assertEquals(result, 536);
}
use of jdk.incubator.foreign.NativeSymbol in project openj9 by eclipse.
the class PrimitiveTypeTests1 method test_addTwoInts_1.
@Test
public void test_addTwoInts_1() throws Throwable {
FunctionDescriptor fd = FunctionDescriptor.of(JAVA_INT, JAVA_INT, JAVA_INT);
NativeSymbol functionSymbol = nativeLibLookup.lookup("add2Ints").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, fd);
int result = (int) mh.invokeExact(112, 123);
Assert.assertEquals(result, 235);
}
use of jdk.incubator.foreign.NativeSymbol in project openj9 by eclipse.
the class PrimitiveTypeTests1 method test_addIntAndChar_1.
@Test
public void test_addIntAndChar_1() throws Throwable {
FunctionDescriptor fd = FunctionDescriptor.of(JAVA_INT, JAVA_INT, JAVA_CHAR);
NativeSymbol functionSymbol = nativeLibLookup.lookup("addIntAndChar").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, fd);
int result = (int) mh.invokeExact(58, 'A');
Assert.assertEquals(result, 123);
}
use of jdk.incubator.foreign.NativeSymbol in project openj9 by eclipse.
the class PrimitiveTypeTests1 method test_generateNewCharFromPointer_1.
@Test
public void test_generateNewCharFromPointer_1() throws Throwable {
FunctionDescriptor fd = FunctionDescriptor.of(JAVA_CHAR, ADDRESS, JAVA_CHAR);
NativeSymbol functionSymbol = nativeLibLookup.lookup("createNewCharFromCharAndCharFromPointer").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, fd);
MemorySegment charSegmt = nativeAllocator.allocate(JAVA_CHAR, 'B');
char result = (char) mh.invoke(charSegmt, 'D');
Assert.assertEquals(result, 'C');
}
Aggregations