use of java.lang.invoke.VarHandle in project openj9 by eclipse.
the class TestVarHandleInfo method testAccessModes.
@Test
public void testAccessModes() throws NoSuchFieldException, IllegalAccessException {
/* grab a VarHandle purely to check the accessModeType */
// $NON-NLS-1$
VarHandle vh = mylookup.findVarHandle(TestVarHandleInfo.class, "instanceField", Integer.class);
for (String methName : accessModes) {
logger.debug(methName);
VarHandle.AccessMode am = VarHandle.AccessMode.valueFromMethodName(methName);
MethodHandle mh = MethodHandles.varHandleExactInvoker(am, vh.accessModeType(am));
checkMethodHandleInfo(mylookup.revealDirect(mh), infos.get(methName), methName);
mh = MethodHandles.varHandleInvoker(am, vh.accessModeType(am));
checkMethodHandleInfo(mylookup.revealDirect(mh), infos.get(methName), methName);
}
}
use of java.lang.invoke.VarHandle in project openj9 by eclipse.
the class StructTests method test_addIntFromPointerAndIntsFromStruct.
@Test
public void test_addIntFromPointerAndIntsFromStruct() throws Throwable {
GroupLayout structLayout = MemoryLayout.ofStruct(C_INT.withName("elem1"), C_INT.withName("elem2"));
VarHandle intHandle1 = structLayout.varHandle(int.class, PathElement.groupElement("elem1"));
VarHandle intHandle2 = structLayout.varHandle(int.class, PathElement.groupElement("elem2"));
MethodType mt = MethodType.methodType(int.class, MemoryAddress.class, MemorySegment.class);
FunctionDescriptor fd = FunctionDescriptor.of(C_INT, C_POINTER, structLayout);
Symbol functionSymbol = nativeLib.lookup("addIntFromPointerAndIntsFromStruct").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, mt, fd);
MemorySegment intSegmt = MemorySegment.allocateNative(C_INT);
MemoryAccess.setInt(intSegmt, 7654321);
MemorySegment structSegmt = MemorySegment.allocateNative(structLayout);
intHandle1.set(structSegmt, 1234567);
intHandle2.set(structSegmt, 2468024);
int result = (int) mh.invokeExact(intSegmt.address(), structSegmt);
Assert.assertEquals(result, 11356912);
structSegmt.close();
intSegmt.close();
}
use of java.lang.invoke.VarHandle in project openj9 by eclipse.
the class StructTests method test_add2IntStructs_returnStruct.
@Test
public void test_add2IntStructs_returnStruct() throws Throwable {
GroupLayout structLayout = MemoryLayout.ofStruct(C_INT.withName("elem1"), C_INT.withName("elem2"));
VarHandle intHandle1 = structLayout.varHandle(int.class, PathElement.groupElement("elem1"));
VarHandle intHandle2 = structLayout.varHandle(int.class, PathElement.groupElement("elem2"));
MethodType mt = MethodType.methodType(MemorySegment.class, MemorySegment.class, MemorySegment.class);
FunctionDescriptor fd = FunctionDescriptor.of(structLayout, structLayout, structLayout);
Symbol functionSymbol = nativeLib.lookup("add2IntStructs_returnStruct").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, mt, fd);
MemorySegment structSegmt1 = MemorySegment.allocateNative(structLayout);
intHandle1.set(structSegmt1, 11223344);
intHandle2.set(structSegmt1, 55667788);
MemorySegment structSegmt2 = MemorySegment.allocateNative(structLayout);
intHandle1.set(structSegmt2, 99001122);
intHandle2.set(structSegmt2, 33445566);
MemorySegment resultSegmt = (MemorySegment) mh.invokeExact(structSegmt1, structSegmt2);
Assert.assertEquals(intHandle1.get(resultSegmt), 110224466);
Assert.assertEquals(intHandle2.get(resultSegmt), 89113354);
structSegmt1.close();
structSegmt2.close();
resultSegmt.close();
}
use of java.lang.invoke.VarHandle in project openj9 by eclipse.
the class StructTests method test_add2ByteStructs_returnStruct.
@Test
public void test_add2ByteStructs_returnStruct() throws Throwable {
GroupLayout structLayout = MemoryLayout.ofStruct(C_CHAR.withName("elem1"), C_CHAR.withName("elem2"));
VarHandle byteHandle1 = structLayout.varHandle(byte.class, PathElement.groupElement("elem1"));
VarHandle byteHandle2 = structLayout.varHandle(byte.class, PathElement.groupElement("elem2"));
MethodType mt = MethodType.methodType(MemorySegment.class, MemorySegment.class, MemorySegment.class);
FunctionDescriptor fd = FunctionDescriptor.of(structLayout, structLayout, structLayout);
Symbol functionSymbol = nativeLib.lookup("add2ByteStructs_returnStruct").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, mt, fd);
MemorySegment structSegmt1 = MemorySegment.allocateNative(structLayout);
byteHandle1.set(structSegmt1, (byte) 25);
byteHandle2.set(structSegmt1, (byte) 11);
MemorySegment structSegmt2 = MemorySegment.allocateNative(structLayout);
byteHandle1.set(structSegmt2, (byte) 24);
byteHandle2.set(structSegmt2, (byte) 13);
MemorySegment resultSegmt = (MemorySegment) mh.invokeExact(structSegmt1, structSegmt2);
Assert.assertEquals((byte) byteHandle1.get(resultSegmt), (byte) 49);
Assert.assertEquals((byte) byteHandle2.get(resultSegmt), (byte) 24);
structSegmt1.close();
structSegmt2.close();
resultSegmt.close();
}
use of java.lang.invoke.VarHandle in project openj9 by eclipse.
the class StructTests method test_add2BoolStructsWithXor_returnStruct.
@Test
public void test_add2BoolStructsWithXor_returnStruct() throws Throwable {
GroupLayout structLayout = MemoryLayout.ofStruct(C_INT.withName("elem1"), C_INT.withName("elem2"));
VarHandle boolHandle1 = structLayout.varHandle(int.class, PathElement.groupElement("elem1"));
VarHandle boolHandle2 = structLayout.varHandle(int.class, PathElement.groupElement("elem2"));
MethodType mt = MethodType.methodType(MemorySegment.class, MemorySegment.class, MemorySegment.class);
FunctionDescriptor fd = FunctionDescriptor.of(structLayout, structLayout, structLayout);
Symbol functionSymbol = nativeLib.lookup("add2BoolStructsWithXor_returnStruct").get();
MethodHandle mh = clinker.downcallHandle(functionSymbol, mt, fd);
MemorySegment structSegmt1 = MemorySegment.allocateNative(structLayout);
boolHandle1.set(structSegmt1, 1);
boolHandle2.set(structSegmt1, 0);
MemorySegment structSegmt2 = MemorySegment.allocateNative(structLayout);
boolHandle1.set(structSegmt2, 1);
boolHandle2.set(structSegmt2, 1);
MemorySegment resultSegmt = (MemorySegment) mh.invokeExact(structSegmt1, structSegmt2);
Assert.assertEquals(boolHandle1.get(resultSegmt), 0);
Assert.assertEquals(boolHandle2.get(resultSegmt), 1);
structSegmt1.close();
structSegmt2.close();
resultSegmt.close();
}
Aggregations