use of jdk.incubator.foreign.MemoryAddress in project tomcat by apache.
the class OpenSSLContext method getCiphers.
private static String[] getCiphers(MemoryAddress sslCtx) {
MemoryAddress sk = SSL_CTX_get_ciphers(sslCtx);
int len = OPENSSL_sk_num(sk);
if (len <= 0) {
return null;
}
ArrayList<String> ciphers = new ArrayList<>(len);
for (int i = 0; i < len; i++) {
MemoryAddress cipher = OPENSSL_sk_value(sk, i);
MemoryAddress cipherName = SSL_CIPHER_get_name(cipher);
ciphers.add(new String(CLinker.toJavaString(cipherName)));
}
return ciphers.toArray(new String[0]);
}
use of jdk.incubator.foreign.MemoryAddress in project tomcat by apache.
the class OpenSSLLifecycleListener method freeDHParameters.
private static void freeDHParameters() {
for (int i = 0; i < dhParameters.length; i++) {
if (dhParameters[i] != null) {
MemoryAddress dh = dhParameters[i].dh;
if (dh != null && !MemoryAddress.NULL.equals(dh)) {
DH_free(dh);
dhParameters[i] = null;
}
}
}
}
use of jdk.incubator.foreign.MemoryAddress in project openj9 by eclipse.
the class StructTests method test_addFloatFromPointerAndFloatsFromStruct_returnFloatPointer.
@Test
public void test_addFloatFromPointerAndFloatsFromStruct_returnFloatPointer() throws Throwable {
GroupLayout structLayout = MemoryLayout.ofStruct(C_FLOAT.withName("elem1"), C_FLOAT.withName("elem2"));
VarHandle floatHandle1 = structLayout.varHandle(float.class, PathElement.groupElement("elem1"));
VarHandle floatHandle2 = structLayout.varHandle(float.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("addFloatFromPointerAndFloatsFromStruct_returnFloatPointer").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, mt, fd);
MemorySegment floatSegmt = MemorySegment.allocateNative(C_FLOAT);
MemoryAccess.setFloat(floatSegmt, 12.12F);
MemorySegment structSegmt = MemorySegment.allocateNative(structLayout);
floatHandle1.set(structSegmt, 18.23F);
floatHandle2.set(structSegmt, 19.34F);
MemoryAddress resultAddr = (MemoryAddress) mh.invokeExact(floatSegmt.address(), structSegmt);
MemorySegment resultSegmt = resultAddr.asSegmentRestricted(C_FLOAT.byteSize());
VarHandle floatHandle = MemoryHandles.varHandle(float.class, ByteOrder.nativeOrder());
float result = (float) floatHandle.get(resultSegmt, 0);
Assert.assertEquals(result, 49.69F, 0.01F);
Assert.assertEquals(resultSegmt.address().toRawLongValue(), floatSegmt.address().toRawLongValue());
floatSegmt.close();
structSegmt.close();
resultSegmt.close();
}
use of jdk.incubator.foreign.MemoryAddress in project openj9 by eclipse.
the class StructTests method test_add2BoolStructsWithXor_returnStructPointer.
@Test
public void test_add2BoolStructsWithXor_returnStructPointer() throws Throwable {
GroupLayout structLayout = MemoryLayout.ofStruct(C_INT.withName("elem1"), C_INT.withName("elem2"));
VarHandle boolHandle1 = structLayout.varHandle(int.class, PathElement.groupElement("elem1"));
VarHandle boolHandle2 = 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("add2BoolStructsWithXor_returnStructPointer").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, mt, fd);
MemorySegment structSegmt1 = MemorySegment.allocateNative(structLayout);
boolHandle1.set(structSegmt1, 1);
boolHandle2.set(structSegmt1, 0);
MemorySegment structSegmt2 = MemorySegment.allocateNative(structLayout);
boolHandle1.set(structSegmt2, 1);
boolHandle2.set(structSegmt2, 1);
MemoryAddress resultAddr = (MemoryAddress) mh.invokeExact(structSegmt1.address(), structSegmt2);
MemorySegment resultSegmt = resultAddr.asSegmentRestricted(structLayout.byteSize());
Assert.assertEquals(boolHandle1.get(resultSegmt), 0);
Assert.assertEquals(boolHandle2.get(resultSegmt), 1);
structSegmt1.close();
structSegmt2.close();
resultSegmt.close();
}
use of jdk.incubator.foreign.MemoryAddress in project openj9 by eclipse.
the class StructTests method test_add2ByteStructs_returnStructPointer.
@Test
public void test_add2ByteStructs_returnStructPointer() throws Throwable {
GroupLayout structLayout = MemoryLayout.ofStruct(C_CHAR.withName("elem1"), C_CHAR.withName("elem2"));
VarHandle byteHandle1 = structLayout.varHandle(byte.class, PathElement.groupElement("elem1"));
VarHandle byteHandle2 = structLayout.varHandle(byte.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("add2ByteStructs_returnStructPointer").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, mt, fd);
MemorySegment structSegmt1 = MemorySegment.allocateNative(structLayout);
byteHandle1.set(structSegmt1, (byte) 25);
byteHandle2.set(structSegmt1, (byte) 11);
MemorySegment structSegmt2 = MemorySegment.allocateNative(structLayout);
byteHandle1.set(structSegmt2, (byte) 24);
byteHandle2.set(structSegmt2, (byte) 13);
MemoryAddress resultAddr = (MemoryAddress) mh.invokeExact(structSegmt1.address(), structSegmt2);
MemorySegment resultSegmt = resultAddr.asSegmentRestricted(structLayout.byteSize());
Assert.assertEquals((byte) byteHandle1.get(resultSegmt), (byte) 49);
Assert.assertEquals((byte) byteHandle2.get(resultSegmt), (byte) 24);
structSegmt1.close();
structSegmt2.close();
resultSegmt.close();
}
Aggregations