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);
}
Aggregations