use of jdk.incubator.foreign.NativeSymbol in project openj9 by eclipse.
the class PrimitiveTypeTests1 method test_addTwoFloats_1.
@Test
public void test_addTwoFloats_1() throws Throwable {
FunctionDescriptor fd = FunctionDescriptor.of(JAVA_FLOAT, JAVA_FLOAT, JAVA_FLOAT);
NativeSymbol functionSymbol = nativeLibLookup.lookup("add2Floats").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, fd);
float result = (float) mh.invokeExact(5.74f, 6.79f);
Assert.assertEquals(result, 12.53f, 0.01f);
}
use of jdk.incubator.foreign.NativeSymbol in project openj9 by eclipse.
the class PrimitiveTypeTests1 method test_addLongAndLongFromPointer_1.
@Test
public void test_addLongAndLongFromPointer_1() throws Throwable {
FunctionDescriptor fd = FunctionDescriptor.of(JAVA_LONG, ADDRESS, JAVA_LONG);
NativeSymbol functionSymbol = nativeLibLookup.lookup("addLongAndLongFromPointer").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, fd);
MemorySegment longSegmt = nativeAllocator.allocate(JAVA_LONG, 57424L);
long result = (long) mh.invoke(longSegmt, 698235L);
Assert.assertEquals(result, 755659L);
}
use of jdk.incubator.foreign.NativeSymbol in project openj9 by eclipse.
the class PrimitiveTypeTests1 method test_memoryAllocFreeFromDefaultLib_1.
@Test
public void test_memoryAllocFreeFromDefaultLib_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) {
NativeSymbol allocSymbol = clinker.lookup("malloc").get();
FunctionDescriptor allocFuncDesc = FunctionDescriptor.of(ADDRESS, JAVA_LONG);
MethodHandle allocHandle = clinker.downcallHandle(allocSymbol, allocFuncDesc);
MemoryAddress allocMemAddr = (MemoryAddress) allocHandle.invokeExact(10L);
allocMemAddr.set(JAVA_INT, 0, 15);
Assert.assertEquals(allocMemAddr.get(JAVA_INT, 0), 15);
NativeSymbol freeSymbol = clinker.lookup("free").get();
FunctionDescriptor freeFuncDesc = FunctionDescriptor.ofVoid(ADDRESS);
MethodHandle freeHandle = clinker.downcallHandle(freeSymbol, freeFuncDesc);
freeHandle.invoke(allocMemAddr);
}
}
use of jdk.incubator.foreign.NativeSymbol in project openj9 by eclipse.
the class PrimitiveTypeTests1 method test_addTwoDoubles_1.
@Test
public void test_addTwoDoubles_1() throws Throwable {
FunctionDescriptor fd = FunctionDescriptor.of(JAVA_DOUBLE, JAVA_DOUBLE, JAVA_DOUBLE);
NativeSymbol functionSymbol = nativeLibLookup.lookup("add2Doubles").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, fd);
double result = (double) mh.invokeExact(159.748d, 262.795d);
Assert.assertEquals(result, 422.543d, 0.001d);
}
use of jdk.incubator.foreign.NativeSymbol in project openj9 by eclipse.
the class PrimitiveTypeTests1 method test_printfFromDefaultLibWithMemAddr_1.
@Test
public void test_printfFromDefaultLibWithMemAddr_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) {
NativeSymbol functionSymbol = clinker.lookup("printf").get();
FunctionDescriptor fd = FunctionDescriptor.of(JAVA_INT, ADDRESS, JAVA_INT, JAVA_INT, JAVA_INT);
MethodHandle mh = clinker.downcallHandle(functionSymbol, fd);
MemorySegment formatSegmt = nativeAllocator.allocateUtf8String("\n%d + %d = %d\n");
mh.invoke(formatSegmt, 15, 27, 42);
}
}
Aggregations