use of jdk.incubator.foreign.SequenceLayout in project openj9 by eclipse.
the class StructTests1 method test_addDoubleAndDoublesFromStructWithNestedStructArray_reverseOrder_1.
@Test
public void test_addDoubleAndDoublesFromStructWithNestedStructArray_reverseOrder_1() throws Throwable {
GroupLayout doubleStruct = MemoryLayout.structLayout(JAVA_DOUBLE.withName("elem1"), JAVA_DOUBLE.withName("elem2"));
SequenceLayout structArray = MemoryLayout.sequenceLayout(2, doubleStruct);
GroupLayout structLayout = MemoryLayout.structLayout(JAVA_DOUBLE.withName("elem1"), structArray.withName("struct_array_elem2"));
FunctionDescriptor fd = FunctionDescriptor.of(JAVA_DOUBLE, JAVA_DOUBLE, structLayout);
NativeSymbol functionSymbol = nativeLibLookup.lookup("addDoubleAndDoublesFromStructWithNestedStructArray_reverseOrder").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_DOUBLE, 0, 111.111D);
structSegmt.set(JAVA_DOUBLE, 8, 222.222D);
structSegmt.set(JAVA_DOUBLE, 16, 333.333D);
structSegmt.set(JAVA_DOUBLE, 24, 444.444D);
structSegmt.set(JAVA_DOUBLE, 32, 555.555D);
double result = (double) mh.invokeExact(666.666D, structSegmt);
Assert.assertEquals(result, 2333.331D, 0.001D);
}
}
use of jdk.incubator.foreign.SequenceLayout in project openj9 by eclipse.
the class StructTests1 method test_addLongAndLongsFromStructWithNestedStructArray_1.
@Test
public void test_addLongAndLongsFromStructWithNestedStructArray_1() throws Throwable {
GroupLayout longStruct = MemoryLayout.structLayout(JAVA_LONG.withName("elem1"), JAVA_LONG.withName("elem2"));
SequenceLayout structArray = MemoryLayout.sequenceLayout(2, longStruct);
GroupLayout structLayout = MemoryLayout.structLayout(structArray.withName("struct_array_elem1"), JAVA_LONG.withName("elem2"));
FunctionDescriptor fd = FunctionDescriptor.of(JAVA_LONG, JAVA_LONG, structLayout);
NativeSymbol functionSymbol = nativeLibLookup.lookup("addLongAndLongsFromStructWithNestedStructArray").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_LONG, 0, 111111111L);
structSegmt.set(JAVA_LONG, 8, 222222222L);
structSegmt.set(JAVA_LONG, 16, 333333333L);
structSegmt.set(JAVA_LONG, 24, 444444444L);
structSegmt.set(JAVA_LONG, 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_addCharAndCharsFromStructWithNestedCharArray_reverseOrder_1.
@Test
public void test_addCharAndCharsFromStructWithNestedCharArray_reverseOrder_1() throws Throwable {
SequenceLayout charArray = MemoryLayout.sequenceLayout(2, JAVA_CHAR);
GroupLayout structLayout = MemoryLayout.structLayout(JAVA_CHAR.withName("elem1"), charArray.withName("array_elem2"), MemoryLayout.paddingLayout(JAVA_CHAR.bitSize()));
FunctionDescriptor fd = FunctionDescriptor.of(JAVA_CHAR, JAVA_CHAR, structLayout);
NativeSymbol functionSymbol = nativeLibLookup.lookup("addCharAndCharsFromStructWithNestedCharArray_reverseOrder").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, 'A');
structSegmt.set(JAVA_CHAR, 2, 'B');
structSegmt.set(JAVA_CHAR, 4, 'C');
char result = (char) mh.invokeExact('D', structSegmt);
Assert.assertEquals(result, 'G');
}
}
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, JAVA_BOOLEAN);
GroupLayout structLayout = MemoryLayout.structLayout(JAVA_BOOLEAN.withName("elem1"), boolArray.withName("array_elem2"), MemoryLayout.paddingLayout(JAVA_BOOLEAN.bitSize()));
FunctionDescriptor fd = FunctionDescriptor.of(JAVA_BOOLEAN, JAVA_BOOLEAN, structLayout);
NativeSymbol functionSymbol = nativeLibLookup.lookup("addBoolAndBoolsFromStructWithNestedBoolArray_reverseOrder").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_BOOLEAN, 0, false);
structSegmt.set(JAVA_BOOLEAN, 1, true);
structSegmt.set(JAVA_BOOLEAN, 2, false);
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_addLongAndLongsFromStructWithNestedLongArray_withoutLayoutName_1.
@Test
public void test_addLongAndLongsFromStructWithNestedLongArray_withoutLayoutName_1() throws Throwable {
SequenceLayout longArray = MemoryLayout.sequenceLayout(2, JAVA_LONG);
GroupLayout structLayout = MemoryLayout.structLayout(longArray, JAVA_LONG);
FunctionDescriptor fd = FunctionDescriptor.of(JAVA_LONG, JAVA_LONG, structLayout);
NativeSymbol functionSymbol = nativeLibLookup.lookup("addLongAndLongsFromStructWithNestedLongArray").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_LONG, 0, 111111111L);
structSegmt.set(JAVA_LONG, 8, 222222222L);
structSegmt.set(JAVA_LONG, 16, 333333333L);
long result = (long) mh.invokeExact(444444444L, structSegmt);
Assert.assertEquals(result, 1111111110L);
}
}
Aggregations