Search in sources :

Example 1 with TypeConfiguration

use of com.oracle.svm.configure.config.TypeConfiguration in project graal by oracle.

the class JniProcessor method processEntry.

@Override
@SuppressWarnings("fallthrough")
void processEntry(Map<String, ?> entry) {
    ConfigurationCondition condition = ConfigurationCondition.alwaysTrue();
    boolean invalidResult = Boolean.FALSE.equals(entry.get("result"));
    if (invalidResult) {
        return;
    }
    String function = (String) entry.get("function");
    String callerClass = (String) entry.get("caller_class");
    List<?> args = (List<?>) entry.get("args");
    LazyValue<String> callerClassLazyValue = lazyValue(callerClass);
    // Special: FindClass and DefineClass take the class in question as a string argument
    if (function.equals("FindClass") || function.equals("DefineClass")) {
        String lookupName = singleElement(args);
        String internalName = (lookupName.charAt(0) != '[') ? ('L' + lookupName + ';') : lookupName;
        String forNameString = MetaUtil.internalNameToJava(internalName, true, true);
        if (!advisor.shouldIgnore(lazyValue(forNameString), callerClassLazyValue)) {
            if (function.equals("FindClass")) {
                configuration.getOrCreateType(condition, forNameString);
            } else if (!AccessAdvisor.PROXY_CLASS_NAME_PATTERN.matcher(lookupName).matches()) {
                // DefineClass
                logWarning("Unsupported JNI function DefineClass used to load class " + forNameString);
            }
        }
        return;
    }
    String clazz = (String) entry.get("class");
    if (advisor.shouldIgnore(lazyValue(clazz), callerClassLazyValue)) {
        return;
    }
    String declaringClass = (String) entry.get("declaring_class");
    String declaringClassOrClazz = (declaringClass != null) ? declaringClass : clazz;
    ConfigurationMemberDeclaration declaration = (declaringClass != null) ? ConfigurationMemberDeclaration.DECLARED : ConfigurationMemberDeclaration.PRESENT;
    TypeConfiguration config = configuration;
    switch(function) {
        case "GetStaticMethodID":
        case "GetMethodID":
            {
                expectSize(args, 2);
                String name = (String) args.get(0);
                String signature = (String) args.get(1);
                if (!advisor.shouldIgnoreJniMethodLookup(lazyValue(clazz), lazyValue(name), lazyValue(signature), callerClassLazyValue)) {
                    config.getOrCreateType(condition, declaringClassOrClazz).addMethod(name, signature, declaration);
                    if (!declaringClassOrClazz.equals(clazz)) {
                        config.getOrCreateType(condition, clazz);
                    }
                }
                break;
            }
        case "GetFieldID":
        case "GetStaticFieldID":
            {
                expectSize(args, 2);
                String name = (String) args.get(0);
                config.getOrCreateType(condition, declaringClassOrClazz).addField(name, declaration, false);
                if (!declaringClassOrClazz.equals(clazz)) {
                    config.getOrCreateType(condition, clazz);
                }
                break;
            }
        case "ThrowNew":
            {
                // exception message, ignore
                expectSize(args, 1);
                String name = ConfigurationMethod.CONSTRUCTOR_NAME;
                String signature = "(Ljava/lang/String;)V";
                if (!advisor.shouldIgnoreJniMethodLookup(lazyValue(clazz), lazyValue(name), lazyValue(signature), callerClassLazyValue)) {
                    config.getOrCreateType(condition, declaringClassOrClazz).addMethod(name, signature, declaration);
                    assert declaringClassOrClazz.equals(clazz) : "Constructor can only be accessed via declaring class";
                }
                break;
            }
        case "ToReflectedField":
            // fall through
            config = reflectionConfiguration;
        case "FromReflectedField":
            {
                expectSize(args, 1);
                String name = (String) args.get(0);
                config.getOrCreateType(condition, declaringClassOrClazz).addField(name, declaration, false);
                break;
            }
        case "ToReflectedMethod":
            // fall through
            config = reflectionConfiguration;
        case "FromReflectedMethod":
            {
                expectSize(args, 2);
                String name = (String) args.get(0);
                String signature = (String) args.get(1);
                config.getOrCreateType(condition, declaringClassOrClazz).addMethod(name, signature, declaration);
                break;
            }
        case "NewObjectArray":
            {
                expectSize(args, 0);
                String arrayQualifiedJavaName = MetaUtil.internalNameToJava(clazz, true, true);
                config.getOrCreateType(condition, arrayQualifiedJavaName);
                break;
            }
    }
}
Also used : ConfigurationCondition(org.graalvm.nativeimage.impl.ConfigurationCondition) ConfigurationMemberDeclaration(com.oracle.svm.configure.config.ConfigurationMemberInfo.ConfigurationMemberDeclaration) List(java.util.List) TypeConfiguration(com.oracle.svm.configure.config.TypeConfiguration)

Example 2 with TypeConfiguration

use of com.oracle.svm.configure.config.TypeConfiguration in project graal by oracle.

the class TypeMethodsWithFlagsTest method doTest.

void doTest() {
    TypeConfiguration currentConfigWithoutPrevious = TypeConfiguration.copyAndSubtract(currentConfig, previousConfig);
    String name = getTypeName();
    ConfigurationType configurationType = currentConfigWithoutPrevious.get(ConfigurationCondition.alwaysTrue(), name);
    if (methodsThatMustExist.size() == 0) {
        Assert.assertNull("Generated configuration type " + name + " exists. Expected it to be cleared as it is empty.", configurationType);
    } else {
        Assert.assertNotNull("Generated configuration type " + name + " does not exist. Has the test code changed?", configurationType);
        for (Map.Entry<ConfigurationMethod, ConfigurationMemberDeclaration> methodEntry : methodsThatMustExist.entrySet()) {
            ConfigurationMemberDeclaration kind = ConfigurationType.TestBackdoor.getMethodInfoIfPresent(configurationType, methodEntry.getKey()).getDeclaration();
            Assert.assertNotNull("Method " + methodEntry.getKey() + " unexpectedly NOT found in the new configuration.", kind);
            Assert.assertEquals("Method " + methodEntry.getKey() + " contains a different kind than expected in the new configuration.", kind, methodEntry.getValue());
        }
        for (Map.Entry<ConfigurationMethod, ConfigurationMemberDeclaration> methodEntry : methodsThatMustNotExist.entrySet()) {
            ConfigurationMemberInfo kind = ConfigurationType.TestBackdoor.getMethodInfoIfPresent(configurationType, methodEntry.getKey());
            Assert.assertNull("Method " + methodEntry.getKey() + " unexpectedly found in the new configuration.", kind);
        }
    }
}
Also used : ConfigurationType(com.oracle.svm.configure.config.ConfigurationType) ConfigurationMethod(com.oracle.svm.configure.config.ConfigurationMethod) ConfigurationMemberInfo(com.oracle.svm.configure.config.ConfigurationMemberInfo) ConfigurationMemberDeclaration(com.oracle.svm.configure.config.ConfigurationMemberInfo.ConfigurationMemberDeclaration) TypeConfiguration(com.oracle.svm.configure.config.TypeConfiguration) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with TypeConfiguration

use of com.oracle.svm.configure.config.TypeConfiguration in project graal by oracle.

the class ConfigurationWithOriginsResultWriter method createNewTraceProcessor.

private TraceProcessor createNewTraceProcessor() {
    TypeConfiguration jniConfig = new TypeConfiguration();
    TypeConfiguration reflectConfig = new TypeConfiguration();
    ProxyConfiguration proxyConfig = new ProxyConfiguration();
    ResourceConfiguration resourceConfig = new ResourceConfiguration();
    SerializationConfiguration serializationConfiguration = new SerializationConfiguration();
    PredefinedClassesConfiguration predefinedClassesConfiguration = new PredefinedClassesConfiguration(new Path[0], null);
    return new TraceProcessor(advisor, jniConfig, reflectConfig, proxyConfig, resourceConfig, serializationConfiguration, predefinedClassesConfiguration, null);
}
Also used : ProxyConfiguration(com.oracle.svm.configure.config.ProxyConfiguration) TraceProcessor(com.oracle.svm.configure.trace.TraceProcessor) TypeConfiguration(com.oracle.svm.configure.config.TypeConfiguration) SerializationConfiguration(com.oracle.svm.configure.config.SerializationConfiguration) PredefinedClassesConfiguration(com.oracle.svm.configure.config.PredefinedClassesConfiguration) ResourceConfiguration(com.oracle.svm.configure.config.ResourceConfiguration)

Aggregations

TypeConfiguration (com.oracle.svm.configure.config.TypeConfiguration)3 ConfigurationMemberDeclaration (com.oracle.svm.configure.config.ConfigurationMemberInfo.ConfigurationMemberDeclaration)2 ConfigurationMemberInfo (com.oracle.svm.configure.config.ConfigurationMemberInfo)1 ConfigurationMethod (com.oracle.svm.configure.config.ConfigurationMethod)1 ConfigurationType (com.oracle.svm.configure.config.ConfigurationType)1 PredefinedClassesConfiguration (com.oracle.svm.configure.config.PredefinedClassesConfiguration)1 ProxyConfiguration (com.oracle.svm.configure.config.ProxyConfiguration)1 ResourceConfiguration (com.oracle.svm.configure.config.ResourceConfiguration)1 SerializationConfiguration (com.oracle.svm.configure.config.SerializationConfiguration)1 TraceProcessor (com.oracle.svm.configure.trace.TraceProcessor)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 ConfigurationCondition (org.graalvm.nativeimage.impl.ConfigurationCondition)1