Search in sources :

Example 16 with MemoryAddress

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

the class PrimitiveTypeTests2 method test_addTwoBoolsWithOr_fromMemAddr_2.

@Test
public void test_addTwoBoolsWithOr_fromMemAddr_2() 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, allocator, mt, fd);
    boolean result = (boolean) mh.invokeExact(true, false);
    Assert.assertEquals(result, true);
}
Also used : MethodType(java.lang.invoke.MethodType) Addressable(jdk.incubator.foreign.Addressable) FunctionDescriptor(jdk.incubator.foreign.FunctionDescriptor) MemoryAddress(jdk.incubator.foreign.MemoryAddress) MethodHandle(java.lang.invoke.MethodHandle) Test(org.testng.annotations.Test)

Example 17 with MemoryAddress

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

the class PrimitiveTypeTests2 method test_addTwoLongs_fromMemAddr_2.

@Test
public void test_addTwoLongs_fromMemAddr_2() 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();
    MemoryAddress memAddr = functionSymbol.address();
    MethodHandle mh = clinker.downcallHandle(memAddr, allocator, mt, fd);
    long result = (long) mh.invokeExact(57424L, 698235L);
    Assert.assertEquals(result, 755659L);
}
Also used : MethodType(java.lang.invoke.MethodType) Addressable(jdk.incubator.foreign.Addressable) FunctionDescriptor(jdk.incubator.foreign.FunctionDescriptor) MemoryAddress(jdk.incubator.foreign.MemoryAddress) MethodHandle(java.lang.invoke.MethodHandle) Test(org.testng.annotations.Test)

Example 18 with MemoryAddress

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

the class StructTests method test_addIntFromPointerAndIntsFromStruct_returnIntPointer.

@Test
public void test_addIntFromPointerAndIntsFromStruct_returnIntPointer() throws Throwable {
    GroupLayout structLayout = MemoryLayout.ofStruct(C_INT.withName("elem1"), C_INT.withName("elem2"));
    VarHandle intHandle1 = structLayout.varHandle(int.class, PathElement.groupElement("elem1"));
    VarHandle intHandle2 = structLayout.varHandle(int.class, PathElement.groupElement("elem2"));
    MethodType mt = MethodType.methodType(MemoryAddress.class, MemoryAddress.class, MemorySegment.class);
    FunctionDescriptor fd = FunctionDescriptor.of(C_POINTER, C_POINTER, structLayout);
    Symbol functionSymbol = nativeLib.lookup("addIntFromPointerAndIntsFromStruct_returnIntPointer").get();
    MethodHandle mh = clinker.downcallHandle(functionSymbol, mt, fd);
    MemorySegment intSegmt = MemorySegment.allocateNative(C_INT);
    MemoryAccess.setInt(intSegmt, 1122333);
    MemorySegment structSegmt = MemorySegment.allocateNative(structLayout);
    intHandle1.set(structSegmt, 4455666);
    intHandle2.set(structSegmt, 7788999);
    MemoryAddress resultAddr = (MemoryAddress) mh.invokeExact(intSegmt.address(), structSegmt);
    MemorySegment resultSegmt = resultAddr.asSegmentRestricted(C_INT.byteSize());
    VarHandle intHandle = MemoryHandles.varHandle(int.class, ByteOrder.nativeOrder());
    int result = (int) intHandle.get(resultSegmt, 0);
    Assert.assertEquals(result, 13366998);
    Assert.assertEquals(resultSegmt.address().toRawLongValue(), intSegmt.address().toRawLongValue());
    intSegmt.close();
    structSegmt.close();
    resultSegmt.close();
}
Also used : MethodType(java.lang.invoke.MethodType) VarHandle(java.lang.invoke.VarHandle) Symbol(jdk.incubator.foreign.LibraryLookup.Symbol) GroupLayout(jdk.incubator.foreign.GroupLayout) FunctionDescriptor(jdk.incubator.foreign.FunctionDescriptor) MemoryAddress(jdk.incubator.foreign.MemoryAddress) MemorySegment(jdk.incubator.foreign.MemorySegment) MethodHandle(java.lang.invoke.MethodHandle) Test(org.testng.annotations.Test)

Example 19 with MemoryAddress

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

the class StructTests method test_addDoubleFromPointerAndDoublesFromStruct_returnDoublePointer.

@Test
public void test_addDoubleFromPointerAndDoublesFromStruct_returnDoublePointer() throws Throwable {
    GroupLayout structLayout = MemoryLayout.ofStruct(C_DOUBLE.withName("elem1"), C_DOUBLE.withName("elem2"));
    VarHandle doubleHandle1 = structLayout.varHandle(double.class, PathElement.groupElement("elem1"));
    VarHandle doubleHandle2 = structLayout.varHandle(double.class, PathElement.groupElement("elem2"));
    MethodType mt = MethodType.methodType(MemoryAddress.class, MemoryAddress.class, MemorySegment.class);
    FunctionDescriptor fd = FunctionDescriptor.of(C_POINTER, C_POINTER, structLayout);
    Symbol functionSymbol = nativeLib.lookup("addDoubleFromPointerAndDoublesFromStruct_returnDoublePointer").get();
    MethodHandle mh = clinker.downcallHandle(functionSymbol, mt, fd);
    MemorySegment doubleSegmt = MemorySegment.allocateNative(C_DOUBLE);
    MemoryAccess.setDouble(doubleSegmt, 212.123D);
    MemorySegment structSegmt = MemorySegment.allocateNative(structLayout);
    doubleHandle1.set(structSegmt, 218.456D);
    doubleHandle2.set(structSegmt, 219.789D);
    MemoryAddress resultAddr = (MemoryAddress) mh.invokeExact(doubleSegmt.address(), structSegmt);
    MemorySegment resultSegmt = resultAddr.asSegmentRestricted(C_DOUBLE.byteSize());
    VarHandle doubleHandle = MemoryHandles.varHandle(double.class, ByteOrder.nativeOrder());
    double result = (double) doubleHandle.get(resultSegmt, 0);
    Assert.assertEquals(result, 650.368D, 0.001D);
    Assert.assertEquals(resultSegmt.address().toRawLongValue(), doubleSegmt.address().toRawLongValue());
    doubleSegmt.close();
    structSegmt.close();
    resultSegmt.close();
}
Also used : MethodType(java.lang.invoke.MethodType) VarHandle(java.lang.invoke.VarHandle) Symbol(jdk.incubator.foreign.LibraryLookup.Symbol) GroupLayout(jdk.incubator.foreign.GroupLayout) FunctionDescriptor(jdk.incubator.foreign.FunctionDescriptor) MemoryAddress(jdk.incubator.foreign.MemoryAddress) MemorySegment(jdk.incubator.foreign.MemorySegment) MethodHandle(java.lang.invoke.MethodHandle) Test(org.testng.annotations.Test)

Example 20 with MemoryAddress

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

the class StructTests method test_addLongFromPointerAndLongsFromStruct_returnLongPointer.

@Test
public void test_addLongFromPointerAndLongsFromStruct_returnLongPointer() throws Throwable {
    GroupLayout structLayout = MemoryLayout.ofStruct(longLayout.withName("elem1"), longLayout.withName("elem2"));
    VarHandle longHandle1 = structLayout.varHandle(long.class, PathElement.groupElement("elem1"));
    VarHandle longHandle2 = structLayout.varHandle(long.class, PathElement.groupElement("elem2"));
    MethodType mt = MethodType.methodType(MemoryAddress.class, MemoryAddress.class, MemorySegment.class);
    FunctionDescriptor fd = FunctionDescriptor.of(C_POINTER, C_POINTER, structLayout);
    Symbol functionSymbol = nativeLib.lookup("addLongFromPointerAndLongsFromStruct_returnLongPointer").get();
    MethodHandle mh = clinker.downcallHandle(functionSymbol, mt, fd);
    MemorySegment longSegmt = MemorySegment.allocateNative(longLayout);
    MemoryAccess.setLong(longSegmt, 1122334455L);
    MemorySegment structSegmt = MemorySegment.allocateNative(structLayout);
    longHandle1.set(structSegmt, 6677889900L);
    longHandle2.set(structSegmt, 1234567890L);
    MemoryAddress resultAddr = (MemoryAddress) mh.invokeExact(longSegmt.address(), structSegmt);
    MemorySegment resultSegmt = resultAddr.asSegmentRestricted(longLayout.byteSize());
    VarHandle longHandle = MemoryHandles.varHandle(long.class, ByteOrder.nativeOrder());
    long result = (long) longHandle.get(resultSegmt, 0);
    Assert.assertEquals(result, 9034792245L);
    Assert.assertEquals(resultSegmt.address().toRawLongValue(), longSegmt.address().toRawLongValue());
    longSegmt.close();
    structSegmt.close();
    resultSegmt.close();
}
Also used : MethodType(java.lang.invoke.MethodType) VarHandle(java.lang.invoke.VarHandle) Symbol(jdk.incubator.foreign.LibraryLookup.Symbol) GroupLayout(jdk.incubator.foreign.GroupLayout) FunctionDescriptor(jdk.incubator.foreign.FunctionDescriptor) MemoryAddress(jdk.incubator.foreign.MemoryAddress) MemorySegment(jdk.incubator.foreign.MemorySegment) MethodHandle(java.lang.invoke.MethodHandle) Test(org.testng.annotations.Test)

Aggregations

MemoryAddress (jdk.incubator.foreign.MemoryAddress)136 Test (org.testng.annotations.Test)131 MethodHandle (java.lang.invoke.MethodHandle)127 FunctionDescriptor (jdk.incubator.foreign.FunctionDescriptor)127 MemorySegment (jdk.incubator.foreign.MemorySegment)102 MethodType (java.lang.invoke.MethodType)93 GroupLayout (jdk.incubator.foreign.GroupLayout)80 VarHandle (java.lang.invoke.VarHandle)78 ResourceScope (jdk.incubator.foreign.ResourceScope)65 SegmentAllocator (jdk.incubator.foreign.SegmentAllocator)64 Addressable (jdk.incubator.foreign.Addressable)63 NativeSymbol (jdk.incubator.foreign.NativeSymbol)34 Symbol (jdk.incubator.foreign.LibraryLookup.Symbol)30 AbstractEndpoint (org.apache.tomcat.util.net.AbstractEndpoint)4 X509Certificate (java.security.cert.X509Certificate)3 CertificateException (java.security.cert.CertificateException)2 ArrayList (java.util.ArrayList)2 SSLException (javax.net.ssl.SSLException)2 PrivateKey (java.security.PrivateKey)1 X509KeyManager (javax.net.ssl.X509KeyManager)1