use of jdk.incubator.foreign.NativeSymbol in project openj9 by eclipse.
the class StructTests2 method test_addDoubleAndDoublesFromNestedStruct_reverseOrder_2.
@Test
public void test_addDoubleAndDoublesFromNestedStruct_reverseOrder_2() throws Throwable {
GroupLayout nestedStructLayout = MemoryLayout.structLayout(JAVA_DOUBLE.withName("elem1"), JAVA_DOUBLE.withName("elem2"));
GroupLayout structLayout = MemoryLayout.structLayout(JAVA_DOUBLE.withName("elem1"), nestedStructLayout.withName("struct_elem2"));
FunctionDescriptor fd = FunctionDescriptor.of(JAVA_DOUBLE, JAVA_DOUBLE, structLayout);
NativeSymbol functionSymbol = nativeLibLookup.lookup("addDoubleAndDoublesFromNestedStruct_reverseOrder").get();
MethodHandle mh = clinker.downcallHandle(fd);
try (ResourceScope scope = ResourceScope.newConfinedScope()) {
SegmentAllocator allocator = SegmentAllocator.nativeAllocator(scope);
MemorySegment structSegmt = allocator.allocate(structLayout);
structSegmt.set(JAVA_DOUBLE, 0, 31.789D);
structSegmt.set(JAVA_DOUBLE, 8, 33.456D);
structSegmt.set(JAVA_DOUBLE, 16, 35.123D);
double result = (double) mh.invokeExact(functionSymbol, 37.864D, structSegmt);
Assert.assertEquals(result, 138.232D, 0.001D);
}
}
use of jdk.incubator.foreign.NativeSymbol in project openj9 by eclipse.
the class StructTests2 method test_addShortAndShortsFromNestedStruct_reverseOrder_2.
@Test
public void test_addShortAndShortsFromNestedStruct_reverseOrder_2() throws Throwable {
GroupLayout nestedStructLayout = MemoryLayout.structLayout(JAVA_SHORT.withName("elem1"), JAVA_SHORT.withName("elem2"));
GroupLayout structLayout = MemoryLayout.structLayout(JAVA_SHORT.withName("elem1"), nestedStructLayout.withName("struct_elem2"), MemoryLayout.paddingLayout(JAVA_SHORT.bitSize()));
FunctionDescriptor fd = FunctionDescriptor.of(JAVA_SHORT, JAVA_SHORT, structLayout);
NativeSymbol functionSymbol = nativeLibLookup.lookup("addShortAndShortsFromNestedStruct_reverseOrder").get();
MethodHandle mh = clinker.downcallHandle(fd);
try (ResourceScope scope = ResourceScope.newConfinedScope()) {
SegmentAllocator allocator = SegmentAllocator.nativeAllocator(scope);
MemorySegment structSegmt = allocator.allocate(structLayout);
structSegmt.set(JAVA_SHORT, 0, (short) 31);
structSegmt.set(JAVA_SHORT, 2, (short) 33);
structSegmt.set(JAVA_SHORT, 4, (short) 35);
short result = (short) mh.invokeExact(functionSymbol, (short) 37, structSegmt);
Assert.assertEquals(result, 136);
}
}
use of jdk.incubator.foreign.NativeSymbol in project openj9 by eclipse.
the class StructTests2 method test_addIntAndIntLongFromStruct_2.
@Test
public void test_addIntAndIntLongFromStruct_2() throws Throwable {
GroupLayout structLayout = MemoryLayout.structLayout(JAVA_INT.withName("elem1"), MemoryLayout.paddingLayout(JAVA_INT.bitSize()), JAVA_LONG.withName("elem2"));
VarHandle elemHandle1 = structLayout.varHandle(PathElement.groupElement("elem1"));
VarHandle elemHandle2 = structLayout.varHandle(PathElement.groupElement("elem2"));
FunctionDescriptor fd = FunctionDescriptor.of(JAVA_LONG, JAVA_INT, structLayout);
NativeSymbol functionSymbol = nativeLibLookup.lookup("addIntAndIntLongFromStruct").get();
MethodHandle mh = clinker.downcallHandle(fd);
try (ResourceScope scope = ResourceScope.newConfinedScope()) {
SegmentAllocator allocator = SegmentAllocator.nativeAllocator(scope);
MemorySegment structSegmt = allocator.allocate(structLayout);
elemHandle1.set(structSegmt, 11223344);
elemHandle2.set(structSegmt, 667788990011L);
long result = (long) mh.invokeExact(functionSymbol, 22446688, structSegmt);
Assert.assertEquals(result, 667822660043L);
}
}
use of jdk.incubator.foreign.NativeSymbol in project openj9 by eclipse.
the class StructTests2 method test_addDoubleAndDoublesFromStructWithNestedStructArray_2.
@Test
public void test_addDoubleAndDoublesFromStructWithNestedStructArray_2() throws Throwable {
GroupLayout doubleStruct = MemoryLayout.structLayout(JAVA_DOUBLE.withName("elem1"), JAVA_DOUBLE.withName("elem2"));
SequenceLayout structArray = MemoryLayout.sequenceLayout(2, doubleStruct);
GroupLayout structLayout = MemoryLayout.structLayout(structArray.withName("struct_array_elem1"), JAVA_DOUBLE.withName("elem2"));
FunctionDescriptor fd = FunctionDescriptor.of(JAVA_DOUBLE, JAVA_DOUBLE, structLayout);
NativeSymbol functionSymbol = nativeLibLookup.lookup("addDoubleAndDoublesFromStructWithNestedStructArray").get();
MethodHandle mh = clinker.downcallHandle(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(functionSymbol, 666.666D, structSegmt);
Assert.assertEquals(result, 2333.331D, 0.001D);
}
}
use of jdk.incubator.foreign.NativeSymbol in project openj9 by eclipse.
the class StructTests2 method test_addShortAndShortsFromStructPointer_2.
@Test
public void test_addShortAndShortsFromStructPointer_2() throws Throwable {
GroupLayout structLayout = MemoryLayout.structLayout(JAVA_SHORT.withName("elem1"), JAVA_SHORT.withName("elem2"));
VarHandle shortHandle1 = structLayout.varHandle(PathElement.groupElement("elem1"));
VarHandle shortHandle2 = structLayout.varHandle(PathElement.groupElement("elem2"));
FunctionDescriptor fd = FunctionDescriptor.of(JAVA_SHORT, JAVA_SHORT, ADDRESS);
NativeSymbol functionSymbol = nativeLibLookup.lookup("addShortAndShortsFromStructPointer").get();
MethodHandle mh = clinker.downcallHandle(fd);
try (ResourceScope scope = ResourceScope.newConfinedScope()) {
SegmentAllocator allocator = SegmentAllocator.nativeAllocator(scope);
MemorySegment structSegmt = allocator.allocate(structLayout);
shortHandle1.set(structSegmt, (short) 22);
shortHandle2.set(structSegmt, (short) 44);
short result = (short) mh.invoke(functionSymbol, (short) 66, structSegmt);
Assert.assertEquals(result, 132);
}
}
Aggregations