use of jdk.incubator.foreign.Addressable in project openj9 by eclipse.
the class MultiThreadingTests1 method test_twoThreadsWithSameFuncDescriptor.
@Test
public void test_twoThreadsWithSameFuncDescriptor() throws Throwable {
Thread thr1 = new Thread() {
public void run() {
try {
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();
MethodHandle mh = clinker.downcallHandle(functionSymbol, mt, fd);
int result = (int) mh.invokeExact(112, 123);
Assert.assertEquals(result, 235);
} catch (Throwable t) {
throw new RuntimeException(t);
}
}
};
thr1.setUncaughtExceptionHandler(this);
thr1.start();
Thread thr2 = new Thread() {
public void run() {
try {
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();
MethodHandle mh = clinker.downcallHandle(functionSymbol, mt, fd);
int result = (int) mh.invokeExact(235, 439);
Assert.assertEquals(result, 674);
} catch (Throwable t) {
throw new RuntimeException(t);
}
}
};
thr2.setUncaughtExceptionHandler(this);
thr2.start();
thr1.join();
thr2.join();
if (initException != null) {
throw new RuntimeException(initException);
}
}
use of jdk.incubator.foreign.Addressable 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) {
Addressable functionSymbol = defaultLibLookup.lookup("printf").get();
MethodType mt = MethodType.methodType(int.class, MemoryAddress.class, int.class, int.class, int.class);
FunctionDescriptor fd = FunctionDescriptor.of(C_INT, C_POINTER, C_INT, C_INT, C_INT);
MethodHandle mh = clinker.downcallHandle(functionSymbol, mt, fd);
MemorySegment formatMemSegment = CLinker.toCString("\n%d + %d = %d\n", resourceScope);
mh.invoke(formatMemSegment.address(), 15, 27, 42);
}
}
use of jdk.incubator.foreign.Addressable in project openj9 by eclipse.
the class PrimitiveTypeTests1 method test_addTwoFloats_fromMemAddr_1.
@Test
public void test_addTwoFloats_fromMemAddr_1() throws Throwable {
MethodType mt = MethodType.methodType(float.class, float.class, float.class);
FunctionDescriptor fd = FunctionDescriptor.of(C_FLOAT, C_FLOAT, C_FLOAT);
Addressable functionSymbol = nativeLibLookup.lookup("add2Floats").get();
MemoryAddress memAddr = functionSymbol.address();
MethodHandle mh = clinker.downcallHandle(memAddr, mt, fd);
float result = (float) mh.invokeExact(5.74f, 6.79f);
Assert.assertEquals(result, 12.53f, 0.01f);
}
use of jdk.incubator.foreign.Addressable in project openj9 by eclipse.
the class PrimitiveTypeTests1 method test_addBoolAndBoolFromPointerWithOr_1.
@Test
public void test_addBoolAndBoolFromPointerWithOr_1() 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, 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 PrimitiveTypeTests1 method test_addTwoNegtiveShorts_1.
@Test
public void test_addTwoNegtiveShorts_1() throws Throwable {
MethodType mt = MethodType.methodType(short.class, short.class, short.class);
FunctionDescriptor fd = FunctionDescriptor.of(C_SHORT, C_SHORT, C_SHORT);
Addressable functionSymbol = nativeLibLookup.lookup("add2Shorts").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, mt, fd);
short result = (short) mh.invokeExact((short) -24, (short) -32);
Assert.assertEquals(result, (short) -56);
}
Aggregations