Search in sources :

Example 86 with FunctionDescriptor

use of jdk.incubator.foreign.FunctionDescriptor in project openj9 by eclipse.

the class InvalidDownCallTests method test_invalidIntegerTypeOnReturn.

@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "The return type must be .*")
public void test_invalidIntegerTypeOnReturn() throws Throwable {
    MethodType mt = MethodType.methodType(Integer.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);
    fail("Failed to throw out IllegalArgumentException in the case of the Integer return type");
}
Also used : MethodType(java.lang.invoke.MethodType) Addressable(jdk.incubator.foreign.Addressable) FunctionDescriptor(jdk.incubator.foreign.FunctionDescriptor) MethodHandle(java.lang.invoke.MethodHandle) Test(org.testng.annotations.Test)

Example 87 with FunctionDescriptor

use of jdk.incubator.foreign.FunctionDescriptor in project openj9 by eclipse.

the class InvalidDownCallTests method test_invalidByteTypeArgument.

@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "The passed-in argument type at index .*")
public void test_invalidByteTypeArgument() throws Throwable {
    MethodType mt = MethodType.methodType(byte.class, Byte.class, byte.class);
    FunctionDescriptor fd = FunctionDescriptor.of(C_CHAR, C_CHAR, C_CHAR);
    Addressable functionSymbol = nativeLibLookup.lookup("add2Bytes").get();
    MethodHandle mh = clinker.downcallHandle(functionSymbol, mt, fd);
    fail("Failed to throw out IllegalArgumentException in the case of the Byte argument");
}
Also used : MethodType(java.lang.invoke.MethodType) Addressable(jdk.incubator.foreign.Addressable) FunctionDescriptor(jdk.incubator.foreign.FunctionDescriptor) MethodHandle(java.lang.invoke.MethodHandle) Test(org.testng.annotations.Test)

Example 88 with FunctionDescriptor

use of jdk.incubator.foreign.FunctionDescriptor in project openj9 by eclipse.

the class InvalidDownCallTests method test_invalidLongTypeArgument.

@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "The passed-in argument type at index .*")
public void test_invalidLongTypeArgument() throws Throwable {
    MethodType mt = MethodType.methodType(long.class, long.class, Long.class);
    FunctionDescriptor fd = FunctionDescriptor.of(longLayout, longLayout, longLayout);
    Addressable functionSymbol = nativeLibLookup.lookup("add2Longs").get();
    MethodHandle mh = clinker.downcallHandle(functionSymbol, mt, fd);
    fail("Failed to throw out IllegalArgumentException in the case of the Long argument");
}
Also used : MethodType(java.lang.invoke.MethodType) Addressable(jdk.incubator.foreign.Addressable) FunctionDescriptor(jdk.incubator.foreign.FunctionDescriptor) MethodHandle(java.lang.invoke.MethodHandle) Test(org.testng.annotations.Test)

Example 89 with FunctionDescriptor

use of jdk.incubator.foreign.FunctionDescriptor in project openj9 by eclipse.

the class InvalidDownCallTests method test_mismatchedIntArgLayoutWithLongType.

@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "Mismatched size .*")
public void test_mismatchedIntArgLayoutWithLongType() throws Throwable {
    MethodType mt = MethodType.methodType(long.class, long.class, long.class);
    FunctionDescriptor fd = FunctionDescriptor.of(longLayout, longLayout, C_INT);
    Addressable functionSymbol = nativeLibLookup.lookup("add2Longs").get();
    MethodHandle mh = clinker.downcallHandle(functionSymbol, mt, fd);
    fail("Failed to throw out IllegalArgumentException in the case of the mismatched int layout");
}
Also used : MethodType(java.lang.invoke.MethodType) Addressable(jdk.incubator.foreign.Addressable) FunctionDescriptor(jdk.incubator.foreign.FunctionDescriptor) MethodHandle(java.lang.invoke.MethodHandle) Test(org.testng.annotations.Test)

Example 90 with FunctionDescriptor

use of jdk.incubator.foreign.FunctionDescriptor in project openj9 by eclipse.

the class InvalidDownCallTests method test_invalidByteTypeOnReturn.

@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "The return type must be .*")
public void test_invalidByteTypeOnReturn() throws Throwable {
    MethodType mt = MethodType.methodType(Byte.class, byte.class, byte.class);
    FunctionDescriptor fd = FunctionDescriptor.of(C_CHAR, C_CHAR, C_CHAR);
    Addressable functionSymbol = nativeLibLookup.lookup("add2Bytes").get();
    MethodHandle mh = clinker.downcallHandle(functionSymbol, mt, fd);
    fail("Failed to throw out IllegalArgumentException in the case of the Byte return type");
}
Also used : MethodType(java.lang.invoke.MethodType) Addressable(jdk.incubator.foreign.Addressable) FunctionDescriptor(jdk.incubator.foreign.FunctionDescriptor) MethodHandle(java.lang.invoke.MethodHandle) Test(org.testng.annotations.Test)

Aggregations

MethodHandle (java.lang.invoke.MethodHandle)939 FunctionDescriptor (jdk.incubator.foreign.FunctionDescriptor)939 Test (org.testng.annotations.Test)939 MemorySegment (jdk.incubator.foreign.MemorySegment)754 GroupLayout (jdk.incubator.foreign.GroupLayout)675 MethodType (java.lang.invoke.MethodType)605 ResourceScope (jdk.incubator.foreign.ResourceScope)549 SegmentAllocator (jdk.incubator.foreign.SegmentAllocator)541 Addressable (jdk.incubator.foreign.Addressable)432 NativeSymbol (jdk.incubator.foreign.NativeSymbol)334 VarHandle (java.lang.invoke.VarHandle)318 SequenceLayout (jdk.incubator.foreign.SequenceLayout)240 Symbol (jdk.incubator.foreign.LibraryLookup.Symbol)173 MemoryAddress (jdk.incubator.foreign.MemoryAddress)127 VaList (jdk.incubator.foreign.VaList)4