use of java.lang.invoke.VarHandle in project openj9 by eclipse.
the class StructTests1 method test_add2LongStructs_returnStruct_1.
@Test
public void test_add2LongStructs_returnStruct_1() throws Throwable {
GroupLayout structLayout = MemoryLayout.structLayout(longLayout.withName("elem1"), longLayout.withName("elem2"));
VarHandle longHandle1 = structLayout.varHandle(long.class, PathElement.groupElement("elem1"));
VarHandle longHandle2 = structLayout.varHandle(long.class, PathElement.groupElement("elem2"));
MethodType mt = MethodType.methodType(MemorySegment.class, MemorySegment.class, MemorySegment.class);
FunctionDescriptor fd = FunctionDescriptor.of(structLayout, structLayout, structLayout);
Addressable functionSymbol = nativeLibLookup.lookup("add2LongStructs_returnStruct").get();
try (ResourceScope scope = ResourceScope.newConfinedScope()) {
SegmentAllocator allocator = SegmentAllocator.ofScope(scope);
MethodHandle mh = clinker.downcallHandle(functionSymbol, allocator, mt, fd);
MemorySegment structSegmt1 = allocator.allocate(structLayout);
longHandle1.set(structSegmt1, 987654321987L);
longHandle2.set(structSegmt1, 123456789123L);
MemorySegment structSegmt2 = allocator.allocate(structLayout);
longHandle1.set(structSegmt2, 224466880022L);
longHandle2.set(structSegmt2, 113355779911L);
MemorySegment resultSegmt = (MemorySegment) mh.invokeExact(structSegmt1, structSegmt2);
Assert.assertEquals(longHandle1.get(resultSegmt), 1212121202009L);
Assert.assertEquals(longHandle2.get(resultSegmt), 236812569034L);
}
}
use of java.lang.invoke.VarHandle in project openj9 by eclipse.
the class StructTests1 method test_addCharAndCharsFromStructPointer_1.
@Test
public void test_addCharAndCharsFromStructPointer_1() throws Throwable {
GroupLayout structLayout = MemoryLayout.structLayout(C_SHORT.withName("elem1"), C_SHORT.withName("elem2"));
VarHandle charHandle1 = structLayout.varHandle(char.class, PathElement.groupElement("elem1"));
VarHandle charHandle2 = structLayout.varHandle(char.class, PathElement.groupElement("elem2"));
MethodType mt = MethodType.methodType(char.class, char.class, MemoryAddress.class);
FunctionDescriptor fd = FunctionDescriptor.of(C_SHORT, C_SHORT, C_POINTER);
Addressable functionSymbol = nativeLibLookup.lookup("addCharAndCharsFromStructPointer").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, mt, fd);
try (ResourceScope scope = ResourceScope.newConfinedScope()) {
SegmentAllocator allocator = SegmentAllocator.ofScope(scope);
MemorySegment structSegmt = allocator.allocate(structLayout);
charHandle1.set(structSegmt, 'H');
charHandle2.set(structSegmt, 'I');
char result = (char) mh.invokeExact('G', structSegmt.address());
Assert.assertEquals(result, 'V');
}
}
use of java.lang.invoke.VarHandle in project openj9 by eclipse.
the class StructTests1 method test_add3ShortStructs_returnStruct_1.
@Test
public void test_add3ShortStructs_returnStruct_1() throws Throwable {
GroupLayout structLayout = MemoryLayout.structLayout(C_SHORT.withName("elem1"), C_SHORT.withName("elem2"), C_SHORT.withName("elem3"), MemoryLayout.paddingLayout(C_SHORT.bitSize()));
VarHandle shortHandle1 = structLayout.varHandle(short.class, PathElement.groupElement("elem1"));
VarHandle shortHandle2 = structLayout.varHandle(short.class, PathElement.groupElement("elem2"));
VarHandle shortHandle3 = structLayout.varHandle(short.class, PathElement.groupElement("elem3"));
MethodType mt = MethodType.methodType(MemorySegment.class, MemorySegment.class, MemorySegment.class);
FunctionDescriptor fd = FunctionDescriptor.of(structLayout, structLayout, structLayout);
Addressable functionSymbol = nativeLibLookup.lookup("add3ShortStructs_returnStruct").get();
try (ResourceScope scope = ResourceScope.newConfinedScope()) {
SegmentAllocator allocator = SegmentAllocator.ofScope(scope);
MethodHandle mh = clinker.downcallHandle(functionSymbol, allocator, mt, fd);
MemorySegment structSegmt1 = allocator.allocate(structLayout);
shortHandle1.set(structSegmt1, (short) 25);
shortHandle2.set(structSegmt1, (short) 26);
shortHandle3.set(structSegmt1, (short) 27);
MemorySegment structSegmt2 = allocator.allocate(structLayout);
shortHandle1.set(structSegmt2, (short) 34);
shortHandle2.set(structSegmt2, (short) 35);
shortHandle3.set(structSegmt2, (short) 36);
MemorySegment resultSegmt = (MemorySegment) mh.invokeExact(structSegmt1, structSegmt2);
Assert.assertEquals((short) shortHandle1.get(resultSegmt), (short) 59);
Assert.assertEquals((short) shortHandle2.get(resultSegmt), (short) 61);
Assert.assertEquals((short) shortHandle3.get(resultSegmt), (short) 63);
}
}
use of java.lang.invoke.VarHandle in project openj9 by eclipse.
the class StructTests1 method test_addBoolAndBoolsFromStructWithXor_1.
@Test
public void test_addBoolAndBoolsFromStructWithXor_1() throws Throwable {
GroupLayout structLayout = MemoryLayout.structLayout(C_CHAR.withName("elem1"), C_CHAR.withName("elem2"));
VarHandle boolHandle1 = structLayout.varHandle(byte.class, PathElement.groupElement("elem1"));
VarHandle boolHandle2 = structLayout.varHandle(byte.class, PathElement.groupElement("elem2"));
MethodType mt = MethodType.methodType(boolean.class, boolean.class, MemorySegment.class);
FunctionDescriptor fd = FunctionDescriptor.of(C_CHAR, C_CHAR, structLayout);
Addressable functionSymbol = nativeLibLookup.lookup("addBoolAndBoolsFromStructWithXor").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, mt, fd);
try (ResourceScope scope = ResourceScope.newConfinedScope()) {
SegmentAllocator allocator = SegmentAllocator.ofScope(scope);
MemorySegment structSegmt = allocator.allocate(structLayout);
boolHandle1.set(structSegmt, (byte) 0);
boolHandle2.set(structSegmt, (byte) 1);
boolean result = (boolean) mh.invokeExact(false, structSegmt);
Assert.assertEquals(result, true);
}
}
use of java.lang.invoke.VarHandle in project openj9 by eclipse.
the class StructTests1 method test_addLongFromPointerAndLongsFromStruct_1.
@Test
public void test_addLongFromPointerAndLongsFromStruct_1() throws Throwable {
GroupLayout structLayout = MemoryLayout.structLayout(longLayout.withName("elem1"), longLayout.withName("elem2"));
VarHandle longHandle1 = structLayout.varHandle(long.class, PathElement.groupElement("elem1"));
VarHandle longHandle2 = structLayout.varHandle(long.class, PathElement.groupElement("elem2"));
MethodType mt = MethodType.methodType(long.class, MemoryAddress.class, MemorySegment.class);
FunctionDescriptor fd = FunctionDescriptor.of(longLayout, C_POINTER, structLayout);
Addressable functionSymbol = nativeLibLookup.lookup("addLongFromPointerAndLongsFromStruct").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, mt, fd);
try (ResourceScope scope = ResourceScope.newConfinedScope()) {
SegmentAllocator allocator = SegmentAllocator.ofScope(scope);
MemorySegment longSegmt = allocator.allocate(longLayout);
MemoryAccess.setLong(longSegmt, 1111111111L);
MemorySegment structSegmt = allocator.allocate(structLayout);
longHandle1.set(structSegmt, 3333333333L);
longHandle2.set(structSegmt, 5555555555L);
long result = (long) mh.invokeExact(longSegmt.address(), structSegmt);
Assert.assertEquals(result, 9999999999L);
}
}
Aggregations