Search in sources :

Example 81 with MemoryAddress

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

the class PrimitiveTypeTests method test_addTwoInts_fromMemAddr.

@Test
public void test_addTwoInts_fromMemAddr() throws Throwable {
    MethodType mt = MethodType.methodType(int.class, int.class, int.class);
    FunctionDescriptor fd = FunctionDescriptor.of(C_INT, C_INT, C_INT);
    Symbol functionSymbol = nativeLib.lookup("add2Ints").get();
    MemoryAddress memAddr = functionSymbol.address();
    MethodHandle mh = clinker.downcallHandle(memAddr, mt, fd);
    int result = (int) mh.invokeExact(112, 123);
    Assert.assertEquals(result, 235);
    FunctionDescriptor fd2 = FunctionDescriptor.of(C_INT.withName("int"), C_INT.withName("int"), C_INT.withName("int"));
    mh = clinker.downcallHandle(memAddr, mt, fd2);
    result = (int) mh.invokeExact(234, 567);
    Assert.assertEquals(result, 801);
}
Also used : MethodType(java.lang.invoke.MethodType) Symbol(jdk.incubator.foreign.LibraryLookup.Symbol) FunctionDescriptor(jdk.incubator.foreign.FunctionDescriptor) MemoryAddress(jdk.incubator.foreign.MemoryAddress) MethodHandle(java.lang.invoke.MethodHandle) Test(org.testng.annotations.Test)

Example 82 with MemoryAddress

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

the class PrimitiveTypeTests method test_addTwoBytes_fromMemAddr.

@Test
public void test_addTwoBytes_fromMemAddr() throws Throwable {
    MethodType mt = MethodType.methodType(byte.class, byte.class, byte.class);
    FunctionDescriptor fd = FunctionDescriptor.of(C_CHAR, C_CHAR, C_CHAR);
    Symbol functionSymbol = nativeLib.lookup("add2Bytes").get();
    MemoryAddress memAddr = functionSymbol.address();
    MethodHandle mh = clinker.downcallHandle(memAddr, mt, fd);
    byte result = (byte) mh.invokeExact((byte) 6, (byte) 3);
    Assert.assertEquals(result, (byte) 9);
    FunctionDescriptor fd2 = FunctionDescriptor.of(C_CHAR.withName("char"), C_CHAR.withName("char"), C_CHAR.withName("char"));
    mh = clinker.downcallHandle(memAddr, mt, fd2);
    result = (byte) mh.invokeExact((byte) 6, (byte) 7);
    Assert.assertEquals(result, (byte) 13);
}
Also used : MethodType(java.lang.invoke.MethodType) Symbol(jdk.incubator.foreign.LibraryLookup.Symbol) FunctionDescriptor(jdk.incubator.foreign.FunctionDescriptor) MemoryAddress(jdk.incubator.foreign.MemoryAddress) MethodHandle(java.lang.invoke.MethodHandle) Test(org.testng.annotations.Test)

Example 83 with MemoryAddress

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

the class PrimitiveTypeTests method test_addTwoDoubles_fromMemAddr.

@Test
public void test_addTwoDoubles_fromMemAddr() throws Throwable {
    MethodType mt = MethodType.methodType(double.class, double.class, double.class);
    FunctionDescriptor fd = FunctionDescriptor.of(C_DOUBLE, C_DOUBLE, C_DOUBLE);
    Symbol functionSymbol = nativeLib.lookup("add2Doubles").get();
    MemoryAddress memAddr = functionSymbol.address();
    MethodHandle mh = clinker.downcallHandle(memAddr, mt, fd);
    double result = (double) mh.invokeExact(159.748d, 262.795d);
    Assert.assertEquals(result, 422.543d, 0.001d);
    FunctionDescriptor fd2 = FunctionDescriptor.of(C_DOUBLE.withName("double"), C_DOUBLE.withName("double"), C_DOUBLE.withName("double"));
    mh = clinker.downcallHandle(memAddr, mt, fd2);
    result = (double) mh.invokeExact(1159.748d, 1262.795d);
    Assert.assertEquals(result, 2422.543d, 0.001d);
}
Also used : MethodType(java.lang.invoke.MethodType) Symbol(jdk.incubator.foreign.LibraryLookup.Symbol) FunctionDescriptor(jdk.incubator.foreign.FunctionDescriptor) MemoryAddress(jdk.incubator.foreign.MemoryAddress) MethodHandle(java.lang.invoke.MethodHandle) Test(org.testng.annotations.Test)

Example 84 with MemoryAddress

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

the class PrimitiveTypeTests method test_addTwoBoolsWithOr_fromMemAddr.

@Test
public void test_addTwoBoolsWithOr_fromMemAddr() throws Throwable {
    MethodType mt = MethodType.methodType(boolean.class, boolean.class, boolean.class);
    FunctionDescriptor fd = FunctionDescriptor.of(C_INT, C_INT, C_INT);
    Symbol functionSymbol = nativeLib.lookup("add2BoolsWithOr").get();
    MemoryAddress memAddr = functionSymbol.address();
    MethodHandle mh = clinker.downcallHandle(memAddr, mt, fd);
    boolean result = (boolean) mh.invokeExact(true, false);
    Assert.assertEquals(result, true);
    FunctionDescriptor fd2 = FunctionDescriptor.of(C_INT.withName("int"), C_INT.withName("int"), C_INT.withName("int"));
    mh = clinker.downcallHandle(functionSymbol, mt, fd2);
    result = (boolean) mh.invokeExact(false, true);
    Assert.assertEquals(result, true);
}
Also used : MethodType(java.lang.invoke.MethodType) Symbol(jdk.incubator.foreign.LibraryLookup.Symbol) FunctionDescriptor(jdk.incubator.foreign.FunctionDescriptor) MemoryAddress(jdk.incubator.foreign.MemoryAddress) MethodHandle(java.lang.invoke.MethodHandle) Test(org.testng.annotations.Test)

Example 85 with MemoryAddress

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

the class PrimitiveTypeTests method test_addTwoShorts_fromMemAddr.

@Test
public void test_addTwoShorts_fromMemAddr() throws Throwable {
    MethodType mt = MethodType.methodType(short.class, short.class, short.class);
    FunctionDescriptor fd = FunctionDescriptor.of(C_SHORT, C_SHORT, C_SHORT);
    Symbol functionSymbol = nativeLib.lookup("add2Shorts").get();
    MemoryAddress memAddr = functionSymbol.address();
    MethodHandle mh = clinker.downcallHandle(memAddr, mt, fd);
    short result = (short) mh.invokeExact((short) 24, (short) 32);
    Assert.assertEquals(result, (short) 56);
    FunctionDescriptor fd2 = FunctionDescriptor.of(C_SHORT.withName("short"), C_SHORT.withName("short"), C_SHORT.withName("short"));
    mh = clinker.downcallHandle(memAddr, mt, fd2);
    result = (short) mh.invokeExact((short) 12, (short) 34);
    Assert.assertEquals(result, (short) 46);
}
Also used : MethodType(java.lang.invoke.MethodType) Symbol(jdk.incubator.foreign.LibraryLookup.Symbol) FunctionDescriptor(jdk.incubator.foreign.FunctionDescriptor) MemoryAddress(jdk.incubator.foreign.MemoryAddress) 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