use of com.oracle.svm.configure.config.ConfigurationMemberInfo.ConfigurationMemberAccessibility in project graal by oracle.
the class ReflectionProcessor method processEntry.
@Override
@SuppressWarnings("fallthrough")
public void processEntry(Map<String, ?> entry) {
boolean invalidResult = Boolean.FALSE.equals(entry.get("result"));
ConfigurationCondition condition = ConfigurationCondition.alwaysTrue();
if (invalidResult) {
return;
}
String function = (String) entry.get("function");
List<?> args = (List<?>) entry.get("args");
switch(function) {
// always filter based on the caller class.
case "getResource":
case "getResourceAsStream":
case "getSystemResource":
case "getSystemResourceAsStream":
case "getResources":
case "getSystemResources":
String literal = singleElement(args);
String regex = Pattern.quote(literal);
resourceConfiguration.addResourcePattern(condition, regex);
return;
}
String callerClass = (String) entry.get("caller_class");
boolean isLoadClass = function.equals("loadClass");
if (isLoadClass || function.equals("forName") || function.equals("findClass")) {
String name = singleElement(args);
if (isLoadClass) {
// different array syntax
name = MetaUtil.internalNameToJava(MetaUtil.toInternalName(name), true, true);
}
if (!advisor.shouldIgnore(lazyValue(name), lazyValue(callerClass)) && !(isLoadClass && advisor.shouldIgnoreLoadClass(lazyValue(name), lazyValue(callerClass)))) {
configuration.getOrCreateType(condition, name);
}
return;
} else if (function.equals("methodTypeDescriptor")) {
List<String> typeNames = singleElement(args);
for (String type : typeNames) {
if (!advisor.shouldIgnore(lazyValue(type), lazyValue(callerClass))) {
configuration.getOrCreateType(condition, type);
}
}
}
String clazz = (String) entry.get("class");
if (advisor.shouldIgnore(lazyValue(clazz), lazyValue(callerClass))) {
return;
}
ConfigurationMemberDeclaration declaration = ConfigurationMemberDeclaration.PUBLIC;
ConfigurationMemberAccessibility accessibility = ConfigurationMemberAccessibility.QUERIED;
String clazzOrDeclaringClass = entry.containsKey("declaring_class") ? (String) entry.get("declaring_class") : clazz;
switch(function) {
case "getDeclaredFields":
{
configuration.getOrCreateType(condition, clazz).setAllDeclaredFields();
break;
}
case "getFields":
{
configuration.getOrCreateType(condition, clazz).setAllPublicFields();
break;
}
case "getDeclaredMethods":
{
configuration.getOrCreateType(condition, clazz).setAllDeclaredMethods(accessibility);
break;
}
case "asInterfaceInstance":
accessibility = ConfigurationMemberAccessibility.ACCESSED;
// fallthrough
case "getMethods":
{
configuration.getOrCreateType(condition, clazz).setAllPublicMethods(accessibility);
break;
}
case "getDeclaredConstructors":
{
configuration.getOrCreateType(condition, clazz).setAllDeclaredConstructors(accessibility);
break;
}
case "getConstructors":
{
configuration.getOrCreateType(condition, clazz).setAllPublicConstructors(accessibility);
break;
}
case "getDeclaredClasses":
{
configuration.getOrCreateType(condition, clazz).setAllDeclaredClasses();
break;
}
case "getPermittedSubclasses":
{
configuration.getOrCreateType(condition, clazz).setAllPermittedSubclasses();
break;
}
case "getClasses":
{
configuration.getOrCreateType(condition, clazz).setAllPublicClasses();
break;
}
case "objectFieldOffset":
case "findFieldHandle":
case "unreflectField":
case "getDeclaredField":
declaration = "findFieldHandle".equals(function) ? ConfigurationMemberDeclaration.PRESENT : ConfigurationMemberDeclaration.DECLARED;
// fall through
case "getField":
{
configuration.getOrCreateType(condition, clazzOrDeclaringClass).addField(singleElement(args), declaration, false);
if (!clazzOrDeclaringClass.equals(clazz)) {
configuration.getOrCreateType(condition, clazz);
}
break;
}
case "getDeclaredMethod":
case "findMethodHandle":
case "invokeMethod":
declaration = "getDeclaredMethod".equals(function) ? ConfigurationMemberDeclaration.DECLARED : ConfigurationMemberDeclaration.PRESENT;
// fall through
case "getMethod":
{
accessibility = (function.equals("invokeMethod") || function.equals("findMethodHandle")) ? ConfigurationMemberAccessibility.ACCESSED : ConfigurationMemberAccessibility.QUERIED;
expectSize(args, 2);
String name = (String) args.get(0);
List<?> parameterTypes = (List<?>) args.get(1);
if (parameterTypes == null) {
// tolerated and equivalent to no parameter types
parameterTypes = Collections.emptyList();
}
configuration.getOrCreateType(condition, clazzOrDeclaringClass).addMethod(name, SignatureUtil.toInternalSignature(parameterTypes), declaration, accessibility);
if (!clazzOrDeclaringClass.equals(clazz)) {
configuration.getOrCreateType(condition, clazz);
}
break;
}
case "getDeclaredConstructor":
case "findConstructorHandle":
case "invokeConstructor":
declaration = "getDeclaredConstructor".equals(function) ? ConfigurationMemberDeclaration.DECLARED : ConfigurationMemberDeclaration.PRESENT;
// fall through
case "getConstructor":
{
accessibility = (function.equals("invokeConstructor") || function.equals("findConstructorHandle")) ? ConfigurationMemberAccessibility.ACCESSED : ConfigurationMemberAccessibility.QUERIED;
List<String> parameterTypes = singleElement(args);
if (parameterTypes == null) {
// tolerated and equivalent to no parameter types
parameterTypes = Collections.emptyList();
}
String signature = SignatureUtil.toInternalSignature(parameterTypes);
assert clazz.equals(clazzOrDeclaringClass) : "Constructor can only be accessed via declaring class";
configuration.getOrCreateType(condition, clazzOrDeclaringClass).addMethod(ConfigurationMethod.CONSTRUCTOR_NAME, signature, declaration, accessibility);
break;
}
case "getProxyClass":
{
expectSize(args, 2);
addDynamicProxy((List<?>) args.get(1), lazyValue(callerClass));
break;
}
case "newProxyInstance":
{
expectSize(args, 3);
addDynamicProxy((List<?>) args.get(1), lazyValue(callerClass));
break;
}
case "newMethodHandleProxyInstance":
{
expectSize(args, 1);
addDynamicProxyUnchecked((List<?>) args.get(0), Collections.singletonList("sun.invoke.WrapperInstance"), lazyValue(callerClass));
break;
}
case "getEnclosingConstructor":
case "getEnclosingMethod":
{
String result = (String) entry.get("result");
addFullyQualifiedDeclaredMethod(result);
break;
}
case "newInstance":
{
if (clazz.equals("java.lang.reflect.Array")) {
// reflective array instantiation
configuration.getOrCreateType(condition, (String) args.get(0));
} else {
configuration.getOrCreateType(condition, clazz).addMethod(ConfigurationMethod.CONSTRUCTOR_NAME, "()V", ConfigurationMemberDeclaration.DECLARED, ConfigurationMemberAccessibility.ACCESSED);
}
break;
}
case "getBundleImplJDK8OrEarlier":
{
expectSize(args, 6);
String baseName = (String) args.get(0);
@SuppressWarnings("unchecked") List<String> classNames = (List<String>) args.get(4);
@SuppressWarnings("unchecked") List<String> locales = (List<String>) args.get(5);
resourceConfiguration.addBundle(condition, classNames, locales, baseName);
break;
}
case "getBundleImplJDK11OrLater":
{
expectSize(args, 7);
String baseName = (String) args.get(2);
@SuppressWarnings("unchecked") List<String> classNames = (List<String>) args.get(5);
@SuppressWarnings("unchecked") List<String> locales = (List<String>) args.get(6);
resourceConfiguration.addBundle(condition, classNames, locales, baseName);
break;
}
default:
System.err.println("Unsupported reflection method: " + function);
}
}
Aggregations