use of jdk.incubator.foreign.SequenceLayout in project openj9 by eclipse.
the class StructTests2 method test_addBoolAndBoolsFromStructWithNestedStructArray_withoutLayoutName_2.
@Test
public void test_addBoolAndBoolsFromStructWithNestedStructArray_withoutLayoutName_2() 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(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(functionSymbol, false, structSegmt);
Assert.assertEquals(result, true);
}
}
use of jdk.incubator.foreign.SequenceLayout in project openj9 by eclipse.
the class StructTests1 method test_addShortAndShortsFromStructWithNestedStructArray_1.
@Test
public void test_addShortAndShortsFromStructWithNestedStructArray_1() throws Throwable {
GroupLayout shortStruct = MemoryLayout.structLayout(JAVA_SHORT.withName("elem1"), JAVA_SHORT.withName("elem2"));
SequenceLayout structArray = MemoryLayout.sequenceLayout(2, shortStruct);
GroupLayout structLayout = MemoryLayout.structLayout(structArray.withName("struc_array_elem1"), JAVA_SHORT.withName("elem2"));
FunctionDescriptor fd = FunctionDescriptor.of(JAVA_SHORT, JAVA_SHORT, structLayout);
NativeSymbol functionSymbol = nativeLibLookup.lookup("addShortAndShortsFromStructWithNestedStructArray").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, fd);
try (ResourceScope scope = ResourceScope.newConfinedScope()) {
SegmentAllocator allocator = SegmentAllocator.nativeAllocator(scope);
MemorySegment structSegmt = allocator.allocate(structLayout);
structSegmt.set(JAVA_SHORT, 0, (short) 111);
structSegmt.set(JAVA_SHORT, 2, (short) 222);
structSegmt.set(JAVA_SHORT, 4, (short) 333);
structSegmt.set(JAVA_SHORT, 6, (short) 444);
structSegmt.set(JAVA_SHORT, 8, (short) 555);
short result = (short) mh.invokeExact((short) 666, structSegmt);
Assert.assertEquals(result, 2331);
}
}
use of jdk.incubator.foreign.SequenceLayout in project openj9 by eclipse.
the class StructTests1 method test_addShortAndShortsFromStructWithNestedShortArray_withoutLayoutName_1.
@Test
public void test_addShortAndShortsFromStructWithNestedShortArray_withoutLayoutName_1() throws Throwable {
SequenceLayout shortArray = MemoryLayout.sequenceLayout(2, JAVA_SHORT);
GroupLayout structLayout = MemoryLayout.structLayout(shortArray, JAVA_SHORT, MemoryLayout.paddingLayout(JAVA_SHORT.bitSize()));
FunctionDescriptor fd = FunctionDescriptor.of(JAVA_SHORT, JAVA_SHORT, structLayout);
NativeSymbol functionSymbol = nativeLibLookup.lookup("addShortAndShortsFromStructWithNestedShortArray").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, fd);
try (ResourceScope scope = ResourceScope.newConfinedScope()) {
SegmentAllocator allocator = SegmentAllocator.nativeAllocator(scope);
MemorySegment structSegmt = allocator.allocate(structLayout);
structSegmt.set(JAVA_SHORT, 0, (short) 111);
structSegmt.set(JAVA_SHORT, 2, (short) 222);
structSegmt.set(JAVA_SHORT, 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_addCharAndCharsFromStructWithNestedStructArray_1.
@Test
public void test_addCharAndCharsFromStructWithNestedStructArray_1() throws Throwable {
GroupLayout charStruct = MemoryLayout.structLayout(JAVA_CHAR.withName("elem1"), JAVA_CHAR.withName("elem2"));
SequenceLayout structArray = MemoryLayout.sequenceLayout(2, charStruct);
GroupLayout structLayout = MemoryLayout.structLayout(structArray.withName("struct_array_elem1"), JAVA_CHAR.withName("elem2"));
FunctionDescriptor fd = FunctionDescriptor.of(JAVA_CHAR, JAVA_CHAR, structLayout);
NativeSymbol functionSymbol = nativeLibLookup.lookup("addCharAndCharsFromStructWithNestedStructArray").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, fd);
try (ResourceScope scope = ResourceScope.newConfinedScope()) {
SegmentAllocator allocator = SegmentAllocator.nativeAllocator(scope);
MemorySegment structSegmt = allocator.allocate(structLayout);
structSegmt.set(JAVA_CHAR, 0, 'E');
structSegmt.set(JAVA_CHAR, 2, 'F');
structSegmt.set(JAVA_CHAR, 4, 'G');
structSegmt.set(JAVA_CHAR, 6, 'H');
structSegmt.set(JAVA_CHAR, 8, 'I');
char result = (char) mh.invokeExact('J', structSegmt);
Assert.assertEquals(result, 'h');
}
}
use of jdk.incubator.foreign.SequenceLayout in project openj9 by eclipse.
the class StructTests1 method test_addIntAndIntsFromStructWithNestedIntArray_withoutLayoutName_1.
@Test
public void test_addIntAndIntsFromStructWithNestedIntArray_withoutLayoutName_1() throws Throwable {
SequenceLayout intArray = MemoryLayout.sequenceLayout(2, JAVA_INT);
GroupLayout structLayout = MemoryLayout.structLayout(intArray, JAVA_INT);
FunctionDescriptor fd = FunctionDescriptor.of(JAVA_INT, JAVA_INT, structLayout);
NativeSymbol functionSymbol = nativeLibLookup.lookup("addIntAndIntsFromStructWithNestedIntArray").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, fd);
try (ResourceScope scope = ResourceScope.newConfinedScope()) {
SegmentAllocator allocator = SegmentAllocator.nativeAllocator(scope);
MemorySegment structSegmt = allocator.allocate(structLayout);
structSegmt.set(JAVA_INT, 0, 1111111);
structSegmt.set(JAVA_INT, 4, 2222222);
structSegmt.set(JAVA_INT, 8, 3333333);
int result = (int) mh.invokeExact(4444444, structSegmt);
Assert.assertEquals(result, 11111110);
}
}
Aggregations