Search in sources :

Example 1 with Feature

use of org.graalvm.nativeimage.Feature in project graal by oracle.

the class FeatureHandler method registerFeature.

/**
 * Instantiates the given feature class and (recursively) all feature classes it requires.
 *
 * @param access
 */
@SuppressWarnings("unchecked")
private void registerFeature(Class<?> featureClass, IsInConfigurationAccessImpl access) {
    if (!Feature.class.isAssignableFrom(featureClass)) {
        throw UserError.abort("Class does not implement " + Feature.class.getName() + ": " + featureClass.getName());
    }
    if (registeredFeatures.contains(featureClass)) {
        return;
    }
    /*
         * Immediately add to the registeredFeatures to avoid infinite recursion in case of cyclic
         * dependencies.
         */
    registeredFeatures.add(featureClass);
    Feature feature;
    try {
        Constructor<?> constructor = featureClass.getDeclaredConstructor();
        constructor.setAccessible(true);
        feature = (Feature) constructor.newInstance();
        if (!feature.isInConfiguration(access)) {
            return;
        }
    } catch (NoSuchMethodException | InvocationTargetException | InstantiationException | IllegalAccessException ex) {
        throw VMError.shouldNotReachHere(ex);
    }
    /*
         * All features are automatically added to the VMConfiguration, to allow convenient
         * configuration checks.
         */
    ImageSingletons.add((Class<Feature>) feature.getClass(), feature);
    /*
         * First add dependent features so that initializers are executed in order of dependencies.
         */
    for (Class<? extends Feature> requiredFeatureClass : feature.getRequiredFeatures()) {
        registerFeature(requiredFeatureClass, access);
    }
    featureInstances.add(feature);
}
Also used : GraalFeature(com.oracle.svm.core.graal.GraalFeature) Feature(org.graalvm.nativeimage.Feature) AutomaticFeature(com.oracle.svm.core.annotate.AutomaticFeature) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

AutomaticFeature (com.oracle.svm.core.annotate.AutomaticFeature)1 GraalFeature (com.oracle.svm.core.graal.GraalFeature)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Feature (org.graalvm.nativeimage.Feature)1