use of jdk.incubator.foreign.Addressable in project openj9 by eclipse.
the class InvalidDownCallTests method test_mismatchedByteArgWithShortLayout.
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "Mismatched size .*")
public void test_mismatchedByteArgWithShortLayout() throws Throwable {
MethodType mt = MethodType.methodType(byte.class, byte.class, byte.class);
FunctionDescriptor fd = FunctionDescriptor.of(C_CHAR, C_CHAR, C_SHORT);
Addressable functionSymbol = nativeLibLookup.lookup("add2Bytes").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, mt, fd);
fail("Failed to throw out IllegalArgumentException in the case of the mismatched layout");
}
use of jdk.incubator.foreign.Addressable in project openj9 by eclipse.
the class MultiCallTests method test_twoCallsWithSameFuncDescriptor.
@Test
public void test_twoCallsWithSameFuncDescriptor() 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();
MethodHandle mh = clinker.downcallHandle(functionSymbol, mt, fd);
int result = (int) mh.invokeExact(112, 123);
Assert.assertEquals(result, 235);
mh = clinker.downcallHandle(functionSymbol, mt, fd);
result = (int) mh.invokeExact(235, 439);
Assert.assertEquals(result, 674);
}
use of jdk.incubator.foreign.Addressable in project openj9 by eclipse.
the class MultiCallTests method test_twoCallsWithDiffFuncDescriptor.
@Test
public void test_twoCallsWithDiffFuncDescriptor() throws Throwable {
MethodType mt1 = MethodType.methodType(int.class, int.class, int.class);
FunctionDescriptor fd1 = FunctionDescriptor.of(C_INT, C_INT, C_INT);
Addressable functionSymbol1 = nativeLibLookup.lookup("add2Ints").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol1, mt1, fd1);
int result = (int) mh.invokeExact(112, 123);
Assert.assertEquals(result, 235);
MethodType mt2 = MethodType.methodType(int.class, int.class, int.class, int.class);
FunctionDescriptor fd2 = FunctionDescriptor.of(C_INT, C_INT, C_INT, C_INT);
Addressable functionSymbol2 = nativeLibLookup.lookup("add3Ints").get();
mh = clinker.downcallHandle(functionSymbol2, mt2, fd2);
result = (int) mh.invokeExact(112, 123, 235);
Assert.assertEquals(result, 470);
}
use of jdk.incubator.foreign.Addressable in project openj9 by eclipse.
the class MultiCallTests method test_multiCallsWithSameArgLayouts.
@Test
public void test_multiCallsWithSameArgLayouts() throws Throwable {
MethodType mt1 = MethodType.methodType(int.class, int.class, int.class);
FunctionDescriptor fd = FunctionDescriptor.of(C_INT, C_INT, C_INT);
Addressable functionSymbol1 = nativeLibLookup.lookup("add2Ints").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol1, mt1, fd);
int intResult = (int) mh.invokeExact(112, 123);
Assert.assertEquals(intResult, 235);
mh = clinker.downcallHandle(functionSymbol1, mt1, fd);
intResult = (int) mh.invokeExact(234, 567);
Assert.assertEquals(intResult, 801);
MethodType mt2 = MethodType.methodType(void.class, int.class, int.class);
FunctionDescriptor fd2 = FunctionDescriptor.ofVoid(C_INT, C_INT);
Addressable functionSymbol2 = nativeLibLookup.lookup("add2IntsReturnVoid").get();
mh = clinker.downcallHandle(functionSymbol2, mt2, fd2);
mh.invokeExact(454, 398);
}
use of jdk.incubator.foreign.Addressable in project openj9 by eclipse.
the class MultiThreadingTests2 method test_twoThreadsWithDiffFuncDescriptor.
@Test
public void test_twoThreadsWithDiffFuncDescriptor() 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);
}
}
};
Thread thr2 = new Thread() {
public void run() {
try {
MethodType mt = MethodType.methodType(int.class, int.class, int.class, int.class);
FunctionDescriptor fd = FunctionDescriptor.of(C_INT, C_INT, C_INT, C_INT);
Addressable functionSymbol = nativeLibLookup.lookup("add3Ints").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, mt, fd);
int result = (int) mh.invokeExact(112, 123, 235);
Assert.assertEquals(result, 470);
} catch (Throwable t) {
throw new RuntimeException(t);
}
}
};
thr1.setUncaughtExceptionHandler(this);
thr2.setUncaughtExceptionHandler(this);
thr1.start();
thr2.start();
thr1.join();
thr2.join();
if (initException != null) {
throw new RuntimeException(initException);
}
}
Aggregations