Search in sources :

Example 1 with IsInConfigurationAccessImpl

use of com.oracle.svm.hosted.FeatureImpl.IsInConfigurationAccessImpl in project graal by oracle.

the class FeatureHandler method registerFeatures.

public void registerFeatures(ImageClassLoader loader) {
    IsInConfigurationAccessImpl access = new IsInConfigurationAccessImpl(this, loader);
    for (Class<?> automaticFeature : loader.findAnnotatedClasses(AutomaticFeature.class)) {
        registerFeature(automaticFeature, access);
    }
    String[] featureNames = Options.Features.getValue().split(",");
    for (String featureName : featureNames) {
        if (!featureName.isEmpty()) {
            try {
                registerFeature(Class.forName(featureName, true, loader.getClassLoader()), access);
            } catch (ClassNotFoundException e) {
                throw UserError.abort("feature " + featureName + " class not found on the classpath. Ensure that the name is correct and that the class is on the classpath.");
            }
        }
    }
}
Also used : IsInConfigurationAccessImpl(com.oracle.svm.hosted.FeatureImpl.IsInConfigurationAccessImpl)

Example 2 with IsInConfigurationAccessImpl

use of com.oracle.svm.hosted.FeatureImpl.IsInConfigurationAccessImpl in project graal by oracle.

the class FeatureHandler method registerFeatures.

@SuppressWarnings("unchecked")
public void registerFeatures(ImageClassLoader loader, DebugContext debug) {
    IsInConfigurationAccessImpl access = new IsInConfigurationAccessImpl(this, loader, debug);
    LinkedHashSet<Class<?>> automaticFeatures = new LinkedHashSet<>(loader.findAnnotatedClasses(AutomaticFeature.class, true));
    Map<Class<?>, Class<?>> specificAutomaticFeatures = new HashMap<>();
    for (Class<?> automaticFeature : automaticFeatures) {
        Class<Feature> mostSpecific = (Class<Feature>) automaticFeature;
        boolean foundMostSpecific = false;
        do {
            List<Class<? extends Feature>> featureSubclasses = loader.findSubclasses(mostSpecific, true);
            featureSubclasses.remove(mostSpecific);
            featureSubclasses.removeIf(o -> !automaticFeatures.contains(o));
            if (featureSubclasses.isEmpty()) {
                foundMostSpecific = true;
            } else {
                if (featureSubclasses.size() > 1) {
                    String candidates = featureSubclasses.stream().map(Class::getName).collect(Collectors.joining(" "));
                    VMError.shouldNotReachHere("Ambiguous @AutomaticFeature extension. Conflicting candidates: " + candidates);
                }
                mostSpecific = (Class<Feature>) featureSubclasses.get(0);
            }
        } while (!foundMostSpecific);
        if (mostSpecific != automaticFeature) {
            specificAutomaticFeatures.put(automaticFeature, mostSpecific);
        }
    }
    /* Remove specific since they get registered via their base */
    for (Class<?> specific : specificAutomaticFeatures.values()) {
        automaticFeatures.remove(specific);
    }
    Function<Class<?>, Class<?>> specificClassProvider = specificAutomaticFeatures::get;
    for (Class<?> featureClass : automaticFeatures) {
        registerFeature(featureClass, specificClassProvider, access);
    }
    for (String featureName : OptionUtils.flatten(",", Options.Features.getValue())) {
        try {
            registerFeature(Class.forName(featureName, true, loader.getClassLoader()), specificClassProvider, access);
        } catch (ClassNotFoundException e) {
            throw UserError.abort("Feature %s class not found on the classpath. Ensure that the name is correct and that the class is on the classpath.", featureName);
        }
    }
    if (NativeImageOptions.PrintFeatures.getValue()) {
        ReportUtils.report("feature information", SubstrateOptions.reportsPath(), "feature_info", "csv", out -> {
            out.println("Feature, Required Features");
            for (Feature featureInstance : featureInstances) {
                out.print(featureInstance.getClass().getTypeName());
                String requiredFeaturesString = featureInstance.getRequiredFeatures().stream().map(Class::getTypeName).collect(Collectors.joining(" ", "[", "]"));
                out.print(", ");
                out.println(requiredFeaturesString);
            }
        });
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) HashMap(java.util.HashMap) IsInConfigurationAccessImpl(com.oracle.svm.hosted.FeatureImpl.IsInConfigurationAccessImpl) GraalFeature(com.oracle.svm.core.graal.GraalFeature) AutomaticFeature(com.oracle.svm.core.annotate.AutomaticFeature) Feature(org.graalvm.nativeimage.hosted.Feature) AutomaticFeature(com.oracle.svm.core.annotate.AutomaticFeature)

Aggregations

IsInConfigurationAccessImpl (com.oracle.svm.hosted.FeatureImpl.IsInConfigurationAccessImpl)2 AutomaticFeature (com.oracle.svm.core.annotate.AutomaticFeature)1 GraalFeature (com.oracle.svm.core.graal.GraalFeature)1 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 Feature (org.graalvm.nativeimage.hosted.Feature)1