use of jdk.incubator.foreign.Addressable 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.Addressable 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.Addressable 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);
}
}
use of jdk.incubator.foreign.Addressable in project openj9 by eclipse.
the class PrimitiveTypeTests2 method test_addTwoIntsReturnVoid_fromMemAddr_2.
@Test
public void test_addTwoIntsReturnVoid_fromMemAddr_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();
MemoryAddress memAddr = functionSymbol.address();
MethodHandle mh = clinker.downcallHandle(memAddr, allocator, mt, fd);
mh.invokeExact(454, 398);
}
use of jdk.incubator.foreign.Addressable in project openj9 by eclipse.
the class PrimitiveTypeTests2 method test_generateNewCharFromPointer_2.
@Test
public void test_generateNewCharFromPointer_2() throws Throwable {
MethodType mt = MethodType.methodType(char.class, MemoryAddress.class, char.class);
FunctionDescriptor fd = FunctionDescriptor.of(C_SHORT, C_POINTER, C_SHORT);
Addressable functionSymbol = nativeLibLookup.lookup("createNewCharFromCharAndCharFromPointer").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, allocator, mt, fd);
MemorySegment shortSegmt = MemorySegment.allocateNative(C_SHORT, resourceScope);
MemoryAccess.setChar(shortSegmt, 'B');
char result = (char) mh.invokeExact(shortSegmt.address(), 'D');
Assert.assertEquals(result, 'C');
}
Aggregations