use of jdk.incubator.foreign.NativeSymbol in project openj9 by eclipse.
the class PrimitiveTypeTests1 method test_addTwoNegtiveShorts_1.
@Test
public void test_addTwoNegtiveShorts_1() throws Throwable {
FunctionDescriptor fd = FunctionDescriptor.of(JAVA_SHORT, JAVA_SHORT, JAVA_SHORT);
NativeSymbol functionSymbol = nativeLibLookup.lookup("add2Shorts").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, fd);
short result = (short) mh.invokeExact((short) -24, (short) -32);
Assert.assertEquals(result, (short) -56);
}
use of jdk.incubator.foreign.NativeSymbol in project openj9 by eclipse.
the class PrimitiveTypeTests1 method test_addTwoBytes_1.
@Test
public void test_addTwoBytes_1() throws Throwable {
FunctionDescriptor fd = FunctionDescriptor.of(JAVA_BYTE, JAVA_BYTE, JAVA_BYTE);
NativeSymbol functionSymbol = nativeLibLookup.lookup("add2Bytes").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, fd);
byte result = (byte) mh.invokeExact((byte) 6, (byte) 3);
Assert.assertEquals(result, (byte) 9);
}
use of jdk.incubator.foreign.NativeSymbol in project openj9 by eclipse.
the class StructTests1 method test_add2DoubleStructs_returnStruct_1.
@Test
public void test_add2DoubleStructs_returnStruct_1() throws Throwable {
GroupLayout structLayout = MemoryLayout.structLayout(JAVA_DOUBLE.withName("elem1"), JAVA_DOUBLE.withName("elem2"));
VarHandle doubleHandle1 = structLayout.varHandle(PathElement.groupElement("elem1"));
VarHandle doubleHandle2 = structLayout.varHandle(PathElement.groupElement("elem2"));
FunctionDescriptor fd = FunctionDescriptor.of(structLayout, structLayout, structLayout);
NativeSymbol functionSymbol = nativeLibLookup.lookup("add2DoubleStructs_returnStruct").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, fd);
try (ResourceScope scope = ResourceScope.newConfinedScope()) {
SegmentAllocator allocator = SegmentAllocator.nativeAllocator(scope);
MemorySegment structSegmt1 = allocator.allocate(structLayout);
doubleHandle1.set(structSegmt1, 11.222D);
doubleHandle2.set(structSegmt1, 22.333D);
MemorySegment structSegmt2 = allocator.allocate(structLayout);
doubleHandle1.set(structSegmt2, 33.444D);
doubleHandle2.set(structSegmt2, 44.555D);
MemorySegment resultSegmt = (MemorySegment) mh.invokeExact(allocator, structSegmt1, structSegmt2);
Assert.assertEquals((double) doubleHandle1.get(resultSegmt), 44.666D, 0.001D);
Assert.assertEquals((double) doubleHandle2.get(resultSegmt), 66.888D, 0.001D);
}
}
use of jdk.incubator.foreign.NativeSymbol in project openj9 by eclipse.
the class StructTests1 method test_addFloatAndFloatsFromStructWithNestedStructArray_reverseOrder_1.
@Test
public void test_addFloatAndFloatsFromStructWithNestedStructArray_reverseOrder_1() throws Throwable {
GroupLayout floatStruct = MemoryLayout.structLayout(JAVA_FLOAT.withName("elem1"), JAVA_FLOAT.withName("elem2"));
SequenceLayout structArray = MemoryLayout.sequenceLayout(2, floatStruct);
GroupLayout structLayout = MemoryLayout.structLayout(JAVA_FLOAT.withName("elem1"), structArray.withName("struct_array_elem2"));
FunctionDescriptor fd = FunctionDescriptor.of(JAVA_FLOAT, JAVA_FLOAT, structLayout);
NativeSymbol functionSymbol = nativeLibLookup.lookup("addFloatAndFloatsFromStructWithNestedStructArray_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_FLOAT, 0, 111.11F);
structSegmt.set(JAVA_FLOAT, 4, 222.22F);
structSegmt.set(JAVA_FLOAT, 8, 333.33F);
structSegmt.set(JAVA_FLOAT, 12, 444.44F);
structSegmt.set(JAVA_FLOAT, 16, 555.55F);
float result = (float) mh.invokeExact(666.66F, structSegmt);
Assert.assertEquals(result, 2333.31F, 0.01F);
}
}
use of jdk.incubator.foreign.NativeSymbol in project openj9 by eclipse.
the class StructTests1 method test_addFloatAndFloatsFromStructWithNestedStructArray_withoutLayoutName_1.
@Test
public void test_addFloatAndFloatsFromStructWithNestedStructArray_withoutLayoutName_1() throws Throwable {
GroupLayout floatStruct = MemoryLayout.structLayout(JAVA_FLOAT, JAVA_FLOAT);
SequenceLayout structArray = MemoryLayout.sequenceLayout(2, floatStruct);
GroupLayout structLayout = MemoryLayout.structLayout(structArray, JAVA_FLOAT);
FunctionDescriptor fd = FunctionDescriptor.of(JAVA_FLOAT, JAVA_FLOAT, structLayout);
NativeSymbol functionSymbol = nativeLibLookup.lookup("addFloatAndFloatsFromStructWithNestedStructArray").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);
structSegmt.set(JAVA_FLOAT, 12, 444.44F);
structSegmt.set(JAVA_FLOAT, 16, 555.55F);
float result = (float) mh.invokeExact(666.66F, structSegmt);
Assert.assertEquals(result, 2333.31F, 0.01F);
}
}
Aggregations