use of jdk.incubator.foreign.SequenceLayout in project openj9 by eclipse.
the class StructTests1 method test_addDoubleAndDoublesFromStructWithNestedDoubleArray_1.
@Test
public void test_addDoubleAndDoublesFromStructWithNestedDoubleArray_1() throws Throwable {
SequenceLayout doubleArray = MemoryLayout.sequenceLayout(2, JAVA_DOUBLE);
GroupLayout structLayout = MemoryLayout.structLayout(doubleArray.withName("array_elem1"), JAVA_DOUBLE.withName("elem2"));
FunctionDescriptor fd = FunctionDescriptor.of(JAVA_DOUBLE, JAVA_DOUBLE, structLayout);
NativeSymbol functionSymbol = nativeLibLookup.lookup("addDoubleAndDoublesFromStructWithNestedDoubleArray").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);
double result = (double) mh.invokeExact(444.444D, structSegmt);
Assert.assertEquals(result, 1111.11D, 0.001D);
}
}
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(JAVA_LONG.withName("elem1"), JAVA_LONG.withName("elem2"));
SequenceLayout structArray = MemoryLayout.sequenceLayout(2, longStruct);
GroupLayout structLayout = MemoryLayout.structLayout(JAVA_LONG.withName("elem1"), structArray.withName("struct_array_elem2"));
FunctionDescriptor fd = FunctionDescriptor.of(JAVA_LONG, JAVA_LONG, structLayout);
NativeSymbol functionSymbol = nativeLibLookup.lookup("addLongAndLongsFromStructWithNestedStructArray_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_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_1.
@Test
public void test_addCharAndCharsFromStructWithNestedCharArray_1() throws Throwable {
SequenceLayout charArray = MemoryLayout.sequenceLayout(2, JAVA_CHAR);
GroupLayout structLayout = MemoryLayout.structLayout(charArray.withName("array_elem1"), JAVA_CHAR.withName("elem2"), MemoryLayout.paddingLayout(JAVA_CHAR.bitSize()));
FunctionDescriptor fd = FunctionDescriptor.of(JAVA_CHAR, JAVA_CHAR, structLayout);
NativeSymbol functionSymbol = nativeLibLookup.lookup("addCharAndCharsFromStructWithNestedCharArray").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_addShortAndShortsFromStructWithNestedShortArray_reverseOrder_1.
@Test
public void test_addShortAndShortsFromStructWithNestedShortArray_reverseOrder_1() throws Throwable {
SequenceLayout shortArray = MemoryLayout.sequenceLayout(2, JAVA_SHORT);
GroupLayout structLayout = MemoryLayout.structLayout(JAVA_SHORT.withName("elem1"), shortArray.withName("array_elem2"), MemoryLayout.paddingLayout(JAVA_SHORT.bitSize()));
FunctionDescriptor fd = FunctionDescriptor.of(JAVA_SHORT, JAVA_SHORT, structLayout);
NativeSymbol functionSymbol = nativeLibLookup.lookup("addShortAndShortsFromStructWithNestedShortArray_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_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_addFloatAndFloatsFromStructWithNestedFloatArray_1.
@Test
public void test_addFloatAndFloatsFromStructWithNestedFloatArray_1() throws Throwable {
SequenceLayout floatArray = MemoryLayout.sequenceLayout(2, JAVA_FLOAT);
GroupLayout structLayout = MemoryLayout.structLayout(floatArray.withName("array_elem1"), JAVA_FLOAT.withName("elem2"));
FunctionDescriptor fd = FunctionDescriptor.of(JAVA_FLOAT, JAVA_FLOAT, structLayout);
NativeSymbol functionSymbol = nativeLibLookup.lookup("addFloatAndFloatsFromStructWithNestedFloatArray").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_FLOAT, 0, 111.11F);
structSegmt.set(JAVA_FLOAT, 4, 222.22F);
structSegmt.set(JAVA_FLOAT, 8, 333.33F);
float result = (float) mh.invokeExact(444.44F, structSegmt);
Assert.assertEquals(result, 1111.1F, 0.01F);
}
}
Aggregations