use of jdk.incubator.foreign.MemoryAddress in project openj9 by eclipse.
the class StructTests2 method test_addLongFromPointerAndLongsFromStruct_returnLongPointer_2.
@Test
public void test_addLongFromPointerAndLongsFromStruct_returnLongPointer_2() throws Throwable {
GroupLayout structLayout = MemoryLayout.structLayout(JAVA_LONG.withName("elem1"), JAVA_LONG.withName("elem2"));
VarHandle longHandle1 = structLayout.varHandle(PathElement.groupElement("elem1"));
VarHandle longHandle2 = structLayout.varHandle(PathElement.groupElement("elem2"));
FunctionDescriptor fd = FunctionDescriptor.of(ADDRESS, ADDRESS, structLayout);
NativeSymbol functionSymbol = nativeLibLookup.lookup("addLongFromPointerAndLongsFromStruct_returnLongPointer").get();
MethodHandle mh = clinker.downcallHandle(fd);
try (ResourceScope scope = ResourceScope.newConfinedScope()) {
SegmentAllocator allocator = SegmentAllocator.nativeAllocator(scope);
MemorySegment longSegmt = allocator.allocate(JAVA_LONG, 1122334455L);
MemorySegment structSegmt = allocator.allocate(structLayout);
longHandle1.set(structSegmt, 6677889900L);
longHandle2.set(structSegmt, 1234567890L);
MemoryAddress resultAddr = (MemoryAddress) mh.invoke(functionSymbol, longSegmt, structSegmt);
Assert.assertEquals(resultAddr.get(JAVA_LONG, 0), 9034792245L);
Assert.assertEquals(resultAddr.toRawLongValue(), longSegmt.address().toRawLongValue());
}
}
use of jdk.incubator.foreign.MemoryAddress in project openj9 by eclipse.
the class StructTests2 method test_addIntFromPointerAndIntsFromStruct_returnIntPointer_2.
@Test
public void test_addIntFromPointerAndIntsFromStruct_returnIntPointer_2() throws Throwable {
GroupLayout structLayout = MemoryLayout.structLayout(JAVA_INT.withName("elem1"), JAVA_INT.withName("elem2"));
VarHandle intHandle1 = structLayout.varHandle(PathElement.groupElement("elem1"));
VarHandle intHandle2 = structLayout.varHandle(PathElement.groupElement("elem2"));
FunctionDescriptor fd = FunctionDescriptor.of(ADDRESS, ADDRESS, structLayout);
NativeSymbol functionSymbol = nativeLibLookup.lookup("addIntFromPointerAndIntsFromStruct_returnIntPointer").get();
MethodHandle mh = clinker.downcallHandle(fd);
try (ResourceScope scope = ResourceScope.newConfinedScope()) {
SegmentAllocator allocator = SegmentAllocator.nativeAllocator(scope);
MemorySegment intSegmt = allocator.allocate(JAVA_INT, 1122333);
MemorySegment structSegmt = allocator.allocate(structLayout);
intHandle1.set(structSegmt, 4455666);
intHandle2.set(structSegmt, 7788999);
MemoryAddress resultAddr = (MemoryAddress) mh.invoke(functionSymbol, intSegmt, structSegmt);
Assert.assertEquals(resultAddr.get(JAVA_INT, 0), 13366998);
Assert.assertEquals(resultAddr.toRawLongValue(), intSegmt.address().toRawLongValue());
}
}
use of jdk.incubator.foreign.MemoryAddress in project openj9 by eclipse.
the class StructTests2 method test_add2FloatStructs_returnStructPointer_2.
@Test
public void test_add2FloatStructs_returnStructPointer_2() throws Throwable {
GroupLayout structLayout = MemoryLayout.structLayout(JAVA_FLOAT.withName("elem1"), JAVA_FLOAT.withName("elem2"));
VarHandle floatHandle1 = structLayout.varHandle(PathElement.groupElement("elem1"));
VarHandle floatHandle2 = structLayout.varHandle(PathElement.groupElement("elem2"));
FunctionDescriptor fd = FunctionDescriptor.of(ADDRESS, ADDRESS, structLayout);
NativeSymbol functionSymbol = nativeLibLookup.lookup("add2FloatStructs_returnStructPointer").get();
MethodHandle mh = clinker.downcallHandle(fd);
try (ResourceScope scope = ResourceScope.newConfinedScope()) {
SegmentAllocator allocator = SegmentAllocator.nativeAllocator(scope);
MemorySegment structSegmt1 = allocator.allocate(structLayout);
floatHandle1.set(structSegmt1, 25.12F);
floatHandle2.set(structSegmt1, 11.23F);
MemorySegment structSegmt2 = allocator.allocate(structLayout);
floatHandle1.set(structSegmt2, 24.34F);
floatHandle2.set(structSegmt2, 13.45F);
MemoryAddress resultAddr = (MemoryAddress) mh.invoke(functionSymbol, structSegmt1, structSegmt2);
Assert.assertEquals(resultAddr.get(JAVA_FLOAT, 0), 49.46F, 0.01F);
Assert.assertEquals(resultAddr.get(JAVA_FLOAT, 4), 24.68F, 0.01F);
}
}
use of jdk.incubator.foreign.MemoryAddress in project openj9 by eclipse.
the class StructTests2 method test_addCharFromPointerAndCharsFromStruct_returnCharPointer_2.
@Test
public void test_addCharFromPointerAndCharsFromStruct_returnCharPointer_2() throws Throwable {
GroupLayout structLayout = MemoryLayout.structLayout(JAVA_CHAR.withName("elem1"), JAVA_CHAR.withName("elem2"));
VarHandle charHandle1 = structLayout.varHandle(PathElement.groupElement("elem1"));
VarHandle charHandle2 = structLayout.varHandle(PathElement.groupElement("elem2"));
FunctionDescriptor fd = FunctionDescriptor.of(ADDRESS, ADDRESS, structLayout);
NativeSymbol functionSymbol = nativeLibLookup.lookup("addCharFromPointerAndCharsFromStruct_returnCharPointer").get();
MethodHandle mh = clinker.downcallHandle(fd);
try (ResourceScope scope = ResourceScope.newConfinedScope()) {
SegmentAllocator allocator = SegmentAllocator.nativeAllocator(scope);
MemorySegment charSegmt = allocator.allocate(JAVA_CHAR, 'D');
MemorySegment structSegmt = allocator.allocate(structLayout);
charHandle1.set(structSegmt, 'E');
charHandle2.set(structSegmt, 'F');
MemoryAddress resultAddr = (MemoryAddress) mh.invoke(functionSymbol, charSegmt, structSegmt);
Assert.assertEquals(resultAddr.get(JAVA_CHAR, 0), 'M');
Assert.assertEquals(resultAddr.toRawLongValue(), charSegmt.address().toRawLongValue());
}
}
use of jdk.incubator.foreign.MemoryAddress in project openj9 by eclipse.
the class StructTests2 method test_addByteFromPointerAndBytesFromStruct_returnBytePointer_2.
@Test
public void test_addByteFromPointerAndBytesFromStruct_returnBytePointer_2() throws Throwable {
GroupLayout structLayout = MemoryLayout.structLayout(JAVA_BYTE.withName("elem1"), JAVA_BYTE.withName("elem2"));
VarHandle byteHandle1 = structLayout.varHandle(PathElement.groupElement("elem1"));
VarHandle byteHandle2 = structLayout.varHandle(PathElement.groupElement("elem2"));
FunctionDescriptor fd = FunctionDescriptor.of(ADDRESS, ADDRESS, structLayout);
NativeSymbol functionSymbol = nativeLibLookup.lookup("addByteFromPointerAndBytesFromStruct_returnBytePointer").get();
MethodHandle mh = clinker.downcallHandle(fd);
try (ResourceScope scope = ResourceScope.newConfinedScope()) {
SegmentAllocator allocator = SegmentAllocator.nativeAllocator(scope);
MemorySegment byteSegmt = allocator.allocate(JAVA_BYTE, (byte) 12);
MemorySegment structSegmt = allocator.allocate(structLayout);
byteHandle1.set(structSegmt, (byte) 18);
byteHandle2.set(structSegmt, (byte) 19);
MemoryAddress resultAddr = (MemoryAddress) mh.invoke(functionSymbol, byteSegmt, structSegmt);
Assert.assertEquals(resultAddr.get(JAVA_BYTE, 0), 49);
Assert.assertEquals(resultAddr.toRawLongValue(), byteSegmt.address().toRawLongValue());
}
}
Aggregations