Java Code Examples for java.lang.invoke.VarHandle#AccessMode
The following examples show how to use
java.lang.invoke.VarHandle#AccessMode .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VarHandleBaseTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
TestAccessMode(TestAccessType at) { this.at = at; try { VarHandle.AccessMode vh_am = toAccessMode(); Method m = VarHandle.class.getMethod(vh_am.methodName(), Object[].class); this.returnType = m.getReturnType(); isPolyMorphicInReturnType = returnType != Object.class; } catch (Exception e) { throw new Error(e); } }
Example 2
Source File: VarHandleBaseTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
static List<VarHandle.AccessMode> accessModesOfType(TestAccessType... ats) { Stream<TestAccessMode> s = Stream.of(TestAccessMode.values()); for (TestAccessType at : ats) { s = s.filter(e -> e.isOfType(at)); } return s.map(TestAccessMode::toAccessMode).collect(toList()); }
Example 3
Source File: VarHandleTestReflection.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider = "accessModesProvider", expectedExceptions = IllegalArgumentException.class) public void methodInvocation(VarHandle.AccessMode accessMode) throws Exception { VarHandle v = handle(); // Try a reflective invoke using a Method Method vhm = VarHandle.class.getMethod(accessMode.methodName(), Object[].class); vhm.invoke(v, new Object[]{}); }
Example 4
Source File: VarHandleTestReflection.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider = "accessModesProvider", expectedExceptions = UnsupportedOperationException.class) public void methodHandleInvoke(VarHandle.AccessMode accessMode) throws Throwable { VarHandle v = handle(); // Try a reflective invoke using a MethodHandle MethodHandle mh = MethodHandles.lookup().unreflect( VarHandle.class.getMethod(accessMode.methodName(), Object[].class)); // Use invoke to avoid WrongMethodTypeException for // non-signature-polymorphic return types Object o = (Object) mh.invoke(v, new Object[]{}); }
Example 5
Source File: VarHandleTestReflection.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider = "accessModesProvider", expectedExceptions = IllegalArgumentException.class) public void methodInvocationFromMethodInfo(VarHandle.AccessMode accessMode) throws Exception { VarHandle v = handle(); // Try a reflective invoke using a Method obtained from cracking // a MethodHandle MethodHandle mh = MethodHandles.lookup().unreflect( VarHandle.class.getMethod(accessMode.methodName(), Object[].class)); MethodHandleInfo info = MethodHandles.lookup().revealDirect(mh); Method im = info.reflectAs(Method.class, MethodHandles.lookup()); im.invoke(v, new Object[]{}); }
Example 6
Source File: VarHandleTestReflection.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider = "accessModesProvider", expectedExceptions = IllegalArgumentException.class) public void reflectAsFromVarHandleInvoker(VarHandle.AccessMode accessMode) throws Exception { VarHandle v = handle(); MethodHandle mh = MethodHandles.varHandleInvoker( accessMode, v.accessModeType(accessMode)); MethodHandleInfo info = MethodHandles.lookup().revealDirect(mh); info.reflectAs(Method.class, MethodHandles.lookup()); }
Example 7
Source File: VarHandleTestReflection.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Test(dataProvider = "accessModesProvider", expectedExceptions = IllegalArgumentException.class) public void reflectAsFromFindVirtual(VarHandle.AccessMode accessMode) throws Exception { VarHandle v = handle(); MethodHandle mh = MethodHandles.publicLookup().findVirtual( VarHandle.class, accessMode.methodName(), v.accessModeType(accessMode)); MethodHandleInfo info = MethodHandles.lookup().revealDirect(mh); info.reflectAs(Method.class, MethodHandles.lookup()); }
Example 8
Source File: VarHandleTestAccessModeMethodNames.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static Class<?> getAccessModeReturnType(VarHandle.AccessMode am) throws Exception { Field field_am_at = VarHandle.AccessMode.class.getDeclaredField("at"); field_am_at.setAccessible(true); Field field_at_returnType = field_am_at.getType().getDeclaredField("returnType"); field_at_returnType.setAccessible(true); return (Class<?>) field_at_returnType.get(field_am_at.get(am)); }
Example 9
Source File: VarHandleBaseTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
VarHandle.AccessMode toAccessMode() { return VarHandle.AccessMode.valueOf(name()); }
Example 10
Source File: VarHandleBaseTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
static List<VarHandle.AccessMode> accessModes() { return Stream.of(VarHandle.AccessMode.values()).collect(toList()); }
Example 11
Source File: VarHandleTestAccessModeMethodNames.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Test(dataProvider = "accessModesProvider") public void testMethodName(VarHandle.AccessMode am) { assertEquals(am.methodName(), toMethodName(am.name())); }
Example 12
Source File: VarHandleTestAccessModeMethodNames.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Test(dataProvider = "accessModesProvider") public void testReturnType(VarHandle.AccessMode am) throws Exception { assertEquals(getReturnType(am.methodName()), getAccessModeReturnType(am)); }