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