use of org.graalvm.compiler.nodes.graphbuilderconf.GeneratedPluginFactory in project graal by oracle.
the class HotSpotGraphBuilderPlugins method create.
/**
* Creates a {@link Plugins} object that should be used when running on HotSpot.
*/
public static Plugins create(HotSpotGraalRuntimeProvider graalRuntime, CompilerConfiguration compilerConfiguration, GraalHotSpotVMConfig config, HotSpotWordTypes wordTypes, MetaAccessProvider metaAccess, ConstantReflectionProvider constantReflection, SnippetReflectionProvider snippetReflection, HotSpotHostForeignCallsProvider foreignCalls, ReplacementsImpl replacements, OptionValues options, TargetDescription target) {
InvocationPlugins invocationPlugins = new HotSpotInvocationPlugins(graalRuntime, config, compilerConfiguration, target, options);
Plugins plugins = new Plugins(invocationPlugins);
plugins.appendNodePlugin(new HotSpotExceptionDispatchPlugin(config, wordTypes.getWordKind()));
if (!IS_IN_NATIVE_IMAGE) {
// In libgraal all word related operations have been fully processed so this is unneeded
HotSpotWordOperationPlugin wordOperationPlugin = new HotSpotWordOperationPlugin(snippetReflection, wordTypes);
HotSpotNodePlugin nodePlugin = new HotSpotNodePlugin(wordOperationPlugin);
plugins.appendTypePlugin(nodePlugin);
plugins.appendNodePlugin(nodePlugin);
}
plugins.appendNodePlugin(new MethodHandlePlugin(constantReflection.getMethodHandleAccess(), !config.supportsMethodHandleDeoptimizationEntry()));
plugins.appendInlineInvokePlugin(replacements);
if (InlineDuringParsing.getValue(options)) {
plugins.appendInlineInvokePlugin(new InlineDuringParsingPlugin());
}
if (config.instanceKlassInitThreadOffset != -1) {
plugins.setClassInitializationPlugin(new HotSpotJITClassInitializationPlugin());
}
invocationPlugins.defer(new Runnable() {
@Override
public void run() {
registerObjectPlugins(invocationPlugins, config, replacements);
registerClassPlugins(plugins, config, replacements);
registerSystemPlugins(invocationPlugins);
registerThreadPlugins(invocationPlugins, config, replacements);
registerCallSitePlugins(invocationPlugins);
registerReflectionPlugins(invocationPlugins, replacements, config);
registerAESPlugins(invocationPlugins, config, replacements);
registerCRC32Plugins(invocationPlugins, config, replacements);
registerCRC32CPlugins(invocationPlugins, config, replacements);
registerBigIntegerPlugins(invocationPlugins, config, replacements);
registerSHAPlugins(invocationPlugins, config, replacements);
registerGHASHPlugins(invocationPlugins, config, metaAccess, replacements);
registerCounterModePlugins(invocationPlugins, config, replacements);
registerBase64Plugins(invocationPlugins, config, metaAccess, replacements);
registerUnsafePlugins(invocationPlugins, config, replacements);
StandardGraphBuilderPlugins.registerInvocationPlugins(snippetReflection, invocationPlugins, replacements, true, false, true, graalRuntime.getHostProviders().getLowerer());
registerArrayPlugins(invocationPlugins, replacements, config);
registerStringPlugins(invocationPlugins, replacements, wordTypes, foreignCalls, config);
registerArraysSupportPlugins(invocationPlugins, config, replacements);
registerReferencePlugins(invocationPlugins, replacements);
registerTrufflePlugins(invocationPlugins, wordTypes, config);
}
});
if (!IS_IN_NATIVE_IMAGE) {
// In libgraal all NodeIntrinsics been converted into special nodes so the plugins
// aren't needed.
NodeIntrinsificationProvider nodeIntrinsificationProvider = new NodeIntrinsificationProvider(metaAccess, snippetReflection, foreignCalls, wordTypes, target);
invocationPlugins.defer(() -> {
for (GeneratedPluginFactory factory : GraalServices.load(GeneratedPluginFactory.class)) {
factory.registerPlugins(invocationPlugins, nodeIntrinsificationProvider);
}
});
}
return plugins;
}
use of org.graalvm.compiler.nodes.graphbuilderconf.GeneratedPluginFactory in project graal by oracle.
the class NativeImageGenerator method registerGraphBuilderPlugins.
public static void registerGraphBuilderPlugins(FeatureHandler featureHandler, RuntimeConfiguration runtimeConfig, HostedProviders providers, AnalysisMetaAccess aMetaAccess, AnalysisUniverse aUniverse, HostedMetaAccess hMetaAccess, HostedUniverse hUniverse, NativeLibraries nativeLibs, ImageClassLoader loader, ParsingReason reason, AnnotationSubstitutionProcessor annotationSubstitutionProcessor, ClassInitializationPlugin classInitializationPlugin, ClassInitializationSupport classInitializationSupport, TargetDescription target) {
GraphBuilderConfiguration.Plugins plugins = new GraphBuilderConfiguration.Plugins(new SubstitutionInvocationPlugins(annotationSubstitutionProcessor));
WordOperationPlugin wordOperationPlugin = new SubstrateWordOperationPlugins(providers.getSnippetReflection(), providers.getWordTypes());
SubstrateReplacements replacements = (SubstrateReplacements) providers.getReplacements();
plugins.appendInlineInvokePlugin(replacements);
plugins.appendNodePlugin(new IntrinsifyMethodHandlesInvocationPlugin(reason, providers, aUniverse, hUniverse));
plugins.appendNodePlugin(new DeletedFieldsPlugin());
plugins.appendNodePlugin(new InjectedAccessorsPlugin());
ResolvedJavaType resolvedJavaType = providers.getMetaAccess().lookupJavaType(ClassInitializationTracking.class);
if (resolvedJavaType instanceof AnalysisType) {
((AnalysisType) resolvedJavaType).registerAsReachable();
ResolvedJavaField field = providers.getMetaAccess().lookupJavaField(ReflectionUtil.lookupField(ClassInitializationTracking.class, "IS_IMAGE_BUILD_TIME"));
((AnalysisField) field).registerAsAccessed();
}
plugins.appendNodePlugin(new EarlyConstantFoldLoadFieldPlugin(providers.getMetaAccess(), providers.getSnippetReflection()));
plugins.appendNodePlugin(new ConstantFoldLoadFieldPlugin(classInitializationSupport));
plugins.appendNodePlugin(new CInterfaceInvocationPlugin(providers.getMetaAccess(), providers.getWordTypes(), nativeLibs));
plugins.appendNodePlugin(new LocalizationFeature.CharsetNodePlugin());
plugins.appendInlineInvokePlugin(wordOperationPlugin);
plugins.appendTypePlugin(wordOperationPlugin);
plugins.appendTypePlugin(new TrustedInterfaceTypePlugin());
plugins.appendNodePlugin(wordOperationPlugin);
plugins.setClassInitializationPlugin(classInitializationPlugin);
featureHandler.forEachGraalFeature(feature -> feature.registerGraphBuilderPlugins(providers, plugins, reason));
HostedSnippetReflectionProvider hostedSnippetReflection = new HostedSnippetReflectionProvider(new SubstrateWordTypes(aMetaAccess, FrameAccess.getWordKind()));
HotSpotGraalCompiler compiler = (HotSpotGraalCompiler) HotSpotJVMCIRuntime.runtime().getCompiler();
NodeIntrinsificationProvider nodeIntrinsificationProvider;
if (!SubstrateUtil.isBuildingLibgraal()) {
nodeIntrinsificationProvider = new NodeIntrinsificationProvider(providers.getMetaAccess(), hostedSnippetReflection, providers.getForeignCalls(), providers.getWordTypes(), target);
} else {
nodeIntrinsificationProvider = new NodeIntrinsificationProvider(providers.getMetaAccess(), hostedSnippetReflection, providers.getForeignCalls(), providers.getWordTypes(), target) {
@Override
public <T> T getInjectedArgument(Class<T> type) {
if (type.isAssignableFrom(GraalHotSpotVMConfig.class)) {
return type.cast(compiler.getGraalRuntime().getVMConfig());
}
if (type.isAssignableFrom(HotSpotGraalRuntimeProvider.class)) {
return type.cast(compiler.getGraalRuntime());
}
return super.getInjectedArgument(type);
}
};
}
for (Class<? extends GeneratedPluginFactory> factoryClass : loader.findSubclasses(GeneratedPluginFactory.class, true)) {
if (!Modifier.isAbstract(factoryClass.getModifiers()) && !factoryClass.getName().contains("hotspot")) {
GeneratedPluginFactory factory;
try {
factory = factoryClass.getDeclaredConstructor().newInstance();
} catch (Exception ex) {
throw VMError.shouldNotReachHere(ex);
}
factory.registerPlugins(plugins.getInvocationPlugins(), nodeIntrinsificationProvider);
}
}
final boolean arrayEqualsSubstitution = !SubstrateOptions.useLLVMBackend();
registerInvocationPlugins(providers.getSnippetReflection(), plugins.getInvocationPlugins(), replacements, reason == ParsingReason.JITCompilation, true, arrayEqualsSubstitution, providers.getLowerer());
Architecture architecture = ConfigurationValues.getTarget().arch;
OptionValues options = aUniverse.hostVM().options();
ImageSingletons.lookup(TargetGraphBuilderPlugins.class).register(plugins, replacements, architecture, /* registerForeignCallMath */
false, options);
/*
* When the context is hosted, i.e., ahead-of-time compilation, and after the analysis we
* need the hosted meta access.
*/
MetaAccessProvider pluginsMetaAccess;
if (reason == ParsingReason.PointsToAnalysis || reason == ParsingReason.JITCompilation) {
pluginsMetaAccess = aMetaAccess;
} else {
VMError.guarantee(reason == ParsingReason.AOTCompilation);
pluginsMetaAccess = hMetaAccess;
}
assert pluginsMetaAccess != null;
SubstrateGraphBuilderPlugins.registerInvocationPlugins(annotationSubstitutionProcessor, pluginsMetaAccess, hostedSnippetReflection, plugins.getInvocationPlugins(), replacements, reason);
featureHandler.forEachGraalFeature(feature -> feature.registerInvocationPlugins(providers, hostedSnippetReflection, plugins, reason));
providers.setGraphBuilderPlugins(plugins);
replacements.setGraphBuilderPlugins(plugins);
if (runtimeConfig != null && runtimeConfig.getProviders() instanceof HostedProviders) {
((HostedProviders) runtimeConfig.getProviders()).setGraphBuilderPlugins(plugins);
for (SubstrateBackend backend : runtimeConfig.getBackends()) {
((HostedProviders) backend.getProviders()).setGraphBuilderPlugins(plugins);
}
}
}
Aggregations