use of java.lang.invoke.MethodType in project jdk8u_jdk by JetBrains.
the class AccessControlTest_sibling method test.
@Test
public void test() {
makeCases(lookups());
if (verbosity > 0) {
verbosity += 9;
Method pro_in_self = targetMethod(THIS_CLASS, PROTECTED, methodType(void.class));
testOneAccess(lookupCase("AccessControlTest/public"), pro_in_self, "find");
testOneAccess(lookupCase("Remote_subclass/public"), pro_in_self, "find");
testOneAccess(lookupCase("Remote_subclass"), pro_in_self, "find");
verbosity -= 9;
}
Set<Class<?>> targetClassesDone = new HashSet<>();
for (LookupCase targetCase : CASES) {
Class<?> targetClass = targetCase.lookupClass();
// already saw this one
if (!targetClassesDone.add(targetClass))
continue;
String targetPlace = placeName(targetClass);
// Object, String, not a target
if (targetPlace == null)
continue;
for (int targetAccess : ACCESS_CASES) {
MethodType methodType = methodType(void.class);
Method method = targetMethod(targetClass, targetAccess, methodType);
// Try to access target method from various contexts.
for (LookupCase sourceCase : CASES) {
testOneAccess(sourceCase, method, "find");
testOneAccess(sourceCase, method, "unreflect");
}
}
}
System.out.println("tested " + testCount + " access scenarios; " + testCountFails + " accesses were denied");
}
use of java.lang.invoke.MethodType in project jdk8u_jdk by JetBrains.
the class BigArityTest method MH_hashArguments.
static MethodHandle MH_hashArguments(Class<? extends Object[]> arrayClass, int arity) {
if (arrayClass == Object[].class)
return MH_hashArguments(arity);
ArrayList<Class<?>> ptypes = new ArrayList<>(Collections.<Class<?>>nCopies(arity, arrayClass.getComponentType()));
MethodType mt = MethodType.methodType(Object.class, ptypes);
return MH_hashArguments_VA.asType(mt);
}
use of java.lang.invoke.MethodType in project dubbo-faker by moyada.
the class MethodInvokeHandler method fetchHandleInfo.
@Override
public MethodHandle fetchHandleInfo(String className, String methodName, String returnType, Class<?>[] paramClass) {
Class<?> classType, returnClassType;
try {
classType = ReflectUtil.getClassType(className);
} catch (ClassNotFoundException e) {
throw new InitializeInvokerException("接口类型不存在: " + returnType);
}
try {
returnClassType = ReflectUtil.getClassType(returnType);
} catch (ClassNotFoundException e) {
throw new InitializeInvokerException("结果类型不存在: " + returnType);
}
MethodHandle methodHandle;
MethodHandles.Lookup lookup = MethodHandles.lookup();
try {
// 创建方法信息
MethodType methodType = MethodType.methodType(returnClassType, paramClass);
// 查询方法返回方法具柄
methodHandle = lookup.findVirtual(classType, methodName, methodType);
} catch (NoSuchMethodException e) {
throw new InitializeInvokerException("方法不存在: " + methodName);
} catch (IllegalAccessException e) {
throw new InitializeInvokerException("方法具柄获取失败");
}
return methodHandle;
}
use of java.lang.invoke.MethodType in project jdk8u_jdk by JetBrains.
the class ValueConversions method zeroConstantFunction.
public static MethodHandle zeroConstantFunction(Wrapper wrap) {
WrapperCache cache = CONSTANT_FUNCTIONS[0];
MethodHandle mh = cache.get(wrap);
if (mh != null) {
return mh;
}
// slow path
MethodType type = MethodType.methodType(wrap.primitiveType());
switch(wrap) {
case VOID:
mh = EMPTY;
break;
case OBJECT:
case INT:
case LONG:
case FLOAT:
case DOUBLE:
try {
mh = IMPL_LOOKUP.findStatic(THIS_CLASS, "zero" + wrap.wrapperSimpleName(), type);
} catch (ReflectiveOperationException ex) {
mh = null;
}
break;
}
if (mh != null) {
return cache.put(wrap, mh);
}
// use zeroInt and cast the result
if (wrap.isSubwordOrInt() && wrap != Wrapper.INT) {
mh = MethodHandles.explicitCastArguments(zeroConstantFunction(Wrapper.INT), type);
return cache.put(wrap, mh);
}
throw new IllegalArgumentException("cannot find zero constant for " + wrap);
}
use of java.lang.invoke.MethodType in project jdk8u_jdk by JetBrains.
the class ValueConversions method boxExact.
public static MethodHandle boxExact(Wrapper wrap) {
WrapperCache cache = BOX_CONVERSIONS[0];
MethodHandle mh = cache.get(wrap);
if (mh != null) {
return mh;
}
// look up the method
String name = "box" + wrap.wrapperSimpleName();
MethodType type = boxType(wrap);
try {
mh = IMPL_LOOKUP.findStatic(THIS_CLASS, name, type);
} catch (ReflectiveOperationException ex) {
mh = null;
}
if (mh != null) {
return cache.put(wrap, mh);
}
throw new IllegalArgumentException("cannot find box adapter for " + wrap);
}
Aggregations