use of jdk.incubator.foreign.MemoryAddress in project openj9 by eclipse.
the class PrimitiveTypeTests1 method test_addTwoInts_fromMemAddr_1.
@Test
public void test_addTwoInts_fromMemAddr_1() throws Throwable {
MethodType mt = MethodType.methodType(int.class, int.class, int.class);
FunctionDescriptor fd = FunctionDescriptor.of(C_INT, C_INT, C_INT);
Addressable functionSymbol = nativeLibLookup.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);
}
use of jdk.incubator.foreign.MemoryAddress in project openj9 by eclipse.
the class PrimitiveTypeTests1 method test_addTwoDoubles_fromMemAddr_1.
@Test
public void test_addTwoDoubles_fromMemAddr_1() throws Throwable {
MethodType mt = MethodType.methodType(double.class, double.class, double.class);
FunctionDescriptor fd = FunctionDescriptor.of(C_DOUBLE, C_DOUBLE, C_DOUBLE);
Addressable functionSymbol = nativeLibLookup.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);
}
use of jdk.incubator.foreign.MemoryAddress in project openj9 by eclipse.
the class PrimitiveTypeTests1 method test_addTwoBoolsWithOr_fromMemAddr_1.
@Test
public void test_addTwoBoolsWithOr_fromMemAddr_1() throws Throwable {
MethodType mt = MethodType.methodType(boolean.class, boolean.class, boolean.class);
FunctionDescriptor fd = FunctionDescriptor.of(C_CHAR, C_CHAR, C_CHAR);
Addressable functionSymbol = nativeLibLookup.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);
}
use of jdk.incubator.foreign.MemoryAddress in project openj9 by eclipse.
the class PrimitiveTypeTests1 method test_memoryAllocFreeFromCLinkerMethod_1.
@Test
public void test_memoryAllocFreeFromCLinkerMethod_1() 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) {
MemoryAddress allocMemAddr = CLinker.allocateMemory(10L);
MemorySegment memSeg = allocMemAddr.asSegment(10L, resourceScope);
MemoryAccess.setIntAtOffset(memSeg, 0, 49);
Assert.assertEquals(MemoryAccess.getIntAtOffset(memSeg, 0), 49);
CLinker.freeMemory(allocMemAddr);
}
}
use of jdk.incubator.foreign.MemoryAddress in project openj9 by eclipse.
the class PrimitiveTypeTests1 method test_strlenFromDefaultLibWithMemAddr_fromMemAddr_1.
@Test
public void test_strlenFromDefaultLibWithMemAddr_fromMemAddr_1() 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, mt, fd);
MemorySegment funcMemSegment = CLinker.toCString("JEP389 DOWNCALL TEST SUITES", resourceScope);
long strLength = (long) mh.invokeExact(funcMemSegment.address());
Assert.assertEquals(strLength, 27);
}
}
Aggregations