Search in sources :

Example 96 with MemoryAddress

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

the class PrimitiveTypeTests1 method test_addTwoInts_fromMemAddr_1.

@Test
public void test_addTwoInts_fromMemAddr_1() 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();
    MemoryAddress memAddr = functionSymbol.address();
    MethodHandle mh = clinker.downcallHandle(memAddr, mt, fd);
    int result = (int) mh.invokeExact(112, 123);
    Assert.assertEquals(result, 235);
}
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 97 with MemoryAddress

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

the class PrimitiveTypeTests1 method test_addTwoDoubles_fromMemAddr_1.

@Test
public void test_addTwoDoubles_fromMemAddr_1() throws Throwable {
    MethodType mt = MethodType.methodType(double.class, double.class, double.class);
    FunctionDescriptor fd = FunctionDescriptor.of(C_DOUBLE, C_DOUBLE, C_DOUBLE);
    Addressable functionSymbol = nativeLibLookup.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);
}
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 98 with MemoryAddress

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

the class PrimitiveTypeTests1 method test_addTwoBoolsWithOr_fromMemAddr_1.

@Test
public void test_addTwoBoolsWithOr_fromMemAddr_1() 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, 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 99 with MemoryAddress

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

the class PrimitiveTypeTests1 method test_memoryAllocFreeFromCLinkerMethod_1.

@Test
public void test_memoryAllocFreeFromCLinkerMethod_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) {
        MemoryAddress allocMemAddr = CLinker.allocateMemory(10L);
        MemorySegment memSeg = allocMemAddr.asSegment(10L, resourceScope);
        MemoryAccess.setIntAtOffset(memSeg, 0, 49);
        Assert.assertEquals(MemoryAccess.getIntAtOffset(memSeg, 0), 49);
        CLinker.freeMemory(allocMemAddr);
    }
}
Also used : MemoryAddress(jdk.incubator.foreign.MemoryAddress) MemorySegment(jdk.incubator.foreign.MemorySegment) Test(org.testng.annotations.Test)

Example 100 with MemoryAddress

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

the class PrimitiveTypeTests1 method test_strlenFromDefaultLibWithMemAddr_fromMemAddr_1.

@Test
public void test_strlenFromDefaultLibWithMemAddr_fromMemAddr_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 strlenSymbol = defaultLibLookup.lookup("strlen").get();
        MemoryAddress memAddr = strlenSymbol.address();
        MethodType mt = MethodType.methodType(long.class, MemoryAddress.class);
        FunctionDescriptor fd = FunctionDescriptor.of(longLayout, C_POINTER);
        MethodHandle mh = clinker.downcallHandle(memAddr, mt, fd);
        MemorySegment funcMemSegment = CLinker.toCString("JEP389 DOWNCALL TEST SUITES", resourceScope);
        long strLength = (long) mh.invokeExact(funcMemSegment.address());
        Assert.assertEquals(strLength, 27);
    }
}
Also used : MethodType(java.lang.invoke.MethodType) Addressable(jdk.incubator.foreign.Addressable) 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