use of jdk.incubator.foreign.SequenceLayout in project openj9 by eclipse.
the class StructTests1 method test_addBoolAndBoolsFromStructWithNestedStructArray_withoutLayoutName_1.
@Test
public void test_addBoolAndBoolsFromStructWithNestedStructArray_withoutLayoutName_1() throws Throwable {
GroupLayout boolStruct = MemoryLayout.structLayout(C_CHAR, C_CHAR);
SequenceLayout structArray = MemoryLayout.sequenceLayout(2, boolStruct);
GroupLayout structLayout = MemoryLayout.structLayout(structArray, C_CHAR);
MethodType mt = MethodType.methodType(boolean.class, boolean.class, MemorySegment.class);
FunctionDescriptor fd = FunctionDescriptor.of(C_CHAR, C_CHAR, structLayout);
Addressable functionSymbol = nativeLibLookup.lookup("addBoolAndBoolsFromStructWithNestedStructArray").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, mt, fd);
try (ResourceScope scope = ResourceScope.newConfinedScope()) {
SegmentAllocator allocator = SegmentAllocator.ofScope(scope);
MemorySegment structSegmt = allocator.allocate(structLayout);
MemoryAccess.setByteAtOffset(structSegmt, 0, (byte) 1);
MemoryAccess.setByteAtOffset(structSegmt, 1, (byte) 0);
MemoryAccess.setByteAtOffset(structSegmt, 2, (byte) 1);
MemoryAccess.setByteAtOffset(structSegmt, 3, (byte) 0);
MemoryAccess.setByteAtOffset(structSegmt, 4, (byte) 1);
boolean result = (boolean) mh.invokeExact(false, structSegmt);
Assert.assertEquals(result, true);
}
}
use of jdk.incubator.foreign.SequenceLayout in project openj9 by eclipse.
the class StructTests1 method test_addBoolAndBoolsFromStructWithNestedBoolArray_reverseOrder_1.
@Test
public void test_addBoolAndBoolsFromStructWithNestedBoolArray_reverseOrder_1() throws Throwable {
SequenceLayout boolArray = MemoryLayout.sequenceLayout(2, C_CHAR);
GroupLayout structLayout = MemoryLayout.structLayout(C_CHAR.withName("elem1"), boolArray.withName("array_elem2"), MemoryLayout.paddingLayout(C_CHAR.bitSize()));
MethodType mt = MethodType.methodType(boolean.class, boolean.class, MemorySegment.class);
FunctionDescriptor fd = FunctionDescriptor.of(C_CHAR, C_CHAR, structLayout);
Addressable functionSymbol = nativeLibLookup.lookup("addBoolAndBoolsFromStructWithNestedBoolArray_reverseOrder").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, mt, fd);
try (ResourceScope scope = ResourceScope.newConfinedScope()) {
SegmentAllocator allocator = SegmentAllocator.ofScope(scope);
MemorySegment structSegmt = allocator.allocate(structLayout);
MemoryAccess.setByteAtOffset(structSegmt, 0, (byte) 0);
MemoryAccess.setByteAtOffset(structSegmt, 1, (byte) 1);
MemoryAccess.setByteAtOffset(structSegmt, 2, (byte) 0);
boolean result = (boolean) mh.invokeExact(false, structSegmt);
Assert.assertEquals(result, true);
}
}
use of jdk.incubator.foreign.SequenceLayout in project openj9 by eclipse.
the class StructTests1 method test_addShortAndShortsFromStructWithNestedShortArray_reverseOrder_1.
@Test
public void test_addShortAndShortsFromStructWithNestedShortArray_reverseOrder_1() throws Throwable {
SequenceLayout shortArray = MemoryLayout.sequenceLayout(2, C_SHORT);
GroupLayout structLayout = MemoryLayout.structLayout(C_SHORT.withName("elem1"), shortArray.withName("array_elem2"), MemoryLayout.paddingLayout(C_SHORT.bitSize()));
MethodType mt = MethodType.methodType(short.class, short.class, MemorySegment.class);
FunctionDescriptor fd = FunctionDescriptor.of(C_SHORT, C_SHORT, structLayout);
Addressable functionSymbol = nativeLibLookup.lookup("addShortAndShortsFromStructWithNestedShortArray_reverseOrder").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, mt, fd);
try (ResourceScope scope = ResourceScope.newConfinedScope()) {
SegmentAllocator allocator = SegmentAllocator.ofScope(scope);
MemorySegment structSegmt = allocator.allocate(structLayout);
MemoryAccess.setShortAtOffset(structSegmt, 0, (short) 111);
MemoryAccess.setShortAtOffset(structSegmt, 2, (short) 222);
MemoryAccess.setShortAtOffset(structSegmt, 4, (short) 333);
short result = (short) mh.invokeExact((short) 444, structSegmt);
Assert.assertEquals(result, 1110);
}
}
use of jdk.incubator.foreign.SequenceLayout in project openj9 by eclipse.
the class StructTests1 method test_addLongAndLongsFromStructWithNestedStructArray_reverseOrder_1.
@Test
public void test_addLongAndLongsFromStructWithNestedStructArray_reverseOrder_1() throws Throwable {
GroupLayout longStruct = MemoryLayout.structLayout(longLayout.withName("elem1"), longLayout.withName("elem2"));
SequenceLayout structArray = MemoryLayout.sequenceLayout(2, longStruct);
GroupLayout structLayout = MemoryLayout.structLayout(longLayout.withName("elem1"), structArray.withName("struct_array_elem2"));
MethodType mt = MethodType.methodType(long.class, long.class, MemorySegment.class);
FunctionDescriptor fd = FunctionDescriptor.of(longLayout, longLayout, structLayout);
Addressable functionSymbol = nativeLibLookup.lookup("addLongAndLongsFromStructWithNestedStructArray_reverseOrder").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, mt, fd);
try (ResourceScope scope = ResourceScope.newConfinedScope()) {
SegmentAllocator allocator = SegmentAllocator.ofScope(scope);
MemorySegment structSegmt = allocator.allocate(structLayout);
MemoryAccess.setLongAtOffset(structSegmt, 0, 111111111L);
MemoryAccess.setLongAtOffset(structSegmt, 8, 222222222L);
MemoryAccess.setLongAtOffset(structSegmt, 16, 333333333L);
MemoryAccess.setLongAtOffset(structSegmt, 24, 444444444L);
MemoryAccess.setLongAtOffset(structSegmt, 32, 555555555L);
long result = (long) mh.invokeExact(666666666L, structSegmt);
Assert.assertEquals(result, 2333333331L);
}
}
use of jdk.incubator.foreign.SequenceLayout in project openj9 by eclipse.
the class StructTests1 method test_addIntAndIntsFromStructWithNestedStructArray_reverseOrder_1.
@Test
public void test_addIntAndIntsFromStructWithNestedStructArray_reverseOrder_1() throws Throwable {
GroupLayout intStruct = MemoryLayout.structLayout(C_INT.withName("elem1"), C_INT.withName("elem2"));
SequenceLayout structArray = MemoryLayout.sequenceLayout(2, intStruct);
GroupLayout structLayout = MemoryLayout.structLayout(C_INT.withName("elem1"), structArray.withName("struct_array_elem2"));
MethodType mt = MethodType.methodType(int.class, int.class, MemorySegment.class);
FunctionDescriptor fd = FunctionDescriptor.of(C_INT, C_INT, structLayout);
Addressable functionSymbol = nativeLibLookup.lookup("addIntAndIntsFromStructWithNestedStructArray_reverseOrder").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, mt, fd);
try (ResourceScope scope = ResourceScope.newConfinedScope()) {
SegmentAllocator allocator = SegmentAllocator.ofScope(scope);
MemorySegment structSegmt = allocator.allocate(structLayout);
MemoryAccess.setIntAtOffset(structSegmt, 0, 1111111);
MemoryAccess.setIntAtOffset(structSegmt, 4, 2222222);
MemoryAccess.setIntAtOffset(structSegmt, 8, 3333333);
MemoryAccess.setIntAtOffset(structSegmt, 12, 4444444);
MemoryAccess.setIntAtOffset(structSegmt, 16, 5555555);
int result = (int) mh.invokeExact(6666666, structSegmt);
Assert.assertEquals(result, 23333331);
}
}
Aggregations