use of com.oracle.svm.core.graal.code.SubstrateBackend in project graal by oracle.
the class NativeImageGenerator method createSuites.
public static Suites createSuites(FeatureHandler featureHandler, RuntimeConfiguration runtimeConfig, SnippetReflectionProvider snippetReflection, boolean hosted) {
SubstrateBackend backend = runtimeConfig.getBackendForNormalMethod();
Suites suites;
if (hosted) {
suites = GraalConfiguration.hostedInstance().createSuites(HostedOptionValues.singleton(), hosted);
} else {
suites = GraalConfiguration.runtimeInstance().createSuites(RuntimeOptionValues.singleton(), hosted);
}
return modifySuites(backend, suites, featureHandler, runtimeConfig, snippetReflection, hosted, false);
}
use of com.oracle.svm.core.graal.code.SubstrateBackend in project graal by oracle.
the class GraphPrepareMetaAccessExtensionProvider method beforeAnalysis.
@Override
public void beforeAnalysis(BeforeAnalysisAccess c) {
DebugContext debug = DebugContext.forCurrentThread();
// box lowering accesses the caches for those classes and thus needs reflective access
for (JavaKind kind : new JavaKind[] { JavaKind.Boolean, JavaKind.Byte, JavaKind.Char, JavaKind.Double, JavaKind.Float, JavaKind.Int, JavaKind.Long, JavaKind.Short }) {
RuntimeReflection.register(kind.toBoxedJavaClass());
Class<?>[] innerClasses = kind.toBoxedJavaClass().getDeclaredClasses();
if (innerClasses != null && innerClasses.length > 0) {
RuntimeReflection.register(innerClasses[0]);
try {
RuntimeReflection.register(innerClasses[0].getDeclaredField("cache"));
} catch (Throwable t) {
throw debug.handle(t);
}
}
}
BeforeAnalysisAccessImpl config = (BeforeAnalysisAccessImpl) c;
GraalSupport.allocatePhaseStatisticsCache();
populateMatchRuleRegistry();
Function<Providers, SubstrateBackend> backendProvider = GraalSupport.getRuntimeBackendProvider();
ClassInitializationSupport classInitializationSupport = config.getHostVM().getClassInitializationSupport();
Providers originalProviders = GraalAccess.getOriginalProviders();
runtimeConfigBuilder = ImageSingletons.lookup(RuntimeGraalSetup.class).createRuntimeConfigurationBuilder(RuntimeOptionValues.singleton(), config.getHostVM(), config.getUniverse(), config.getMetaAccess(), originalProviders.getConstantReflection(), backendProvider, config.getNativeLibraries(), classInitializationSupport, originalProviders.getLoopsDataProvider()).build();
RuntimeConfiguration runtimeConfig = runtimeConfigBuilder.getRuntimeConfig();
Providers runtimeProviders = runtimeConfig.getProviders();
WordTypes wordTypes = runtimeConfigBuilder.getWordTypes();
hostedProviders = new HostedProviders(runtimeProviders.getMetaAccess(), runtimeProviders.getCodeCache(), runtimeProviders.getConstantReflection(), runtimeProviders.getConstantFieldProvider(), runtimeProviders.getForeignCalls(), runtimeProviders.getLowerer(), runtimeProviders.getReplacements(), runtimeProviders.getStampProvider(), runtimeConfig.getSnippetReflection(), wordTypes, runtimeProviders.getPlatformConfigurationProvider(), new GraphPrepareMetaAccessExtensionProvider(), runtimeProviders.getLoopsDataProvider());
SubstrateGraalRuntime graalRuntime = new SubstrateGraalRuntime();
objectReplacer.setGraalRuntime(graalRuntime);
ImageSingletons.add(GraalRuntime.class, graalRuntime);
RuntimeSupport.getRuntimeSupport().addShutdownHook(new GraalSupport.GraalShutdownHook());
FeatureHandler featureHandler = config.getFeatureHandler();
NativeImageGenerator.registerGraphBuilderPlugins(featureHandler, runtimeConfig, hostedProviders, config.getMetaAccess(), config.getUniverse(), null, null, config.getNativeLibraries(), config.getImageClassLoader(), ParsingReason.JITCompilation, ((Inflation) config.getBigBang()).getAnnotationSubstitutionProcessor(), new SubstrateClassInitializationPlugin(config.getHostVM()), classInitializationSupport, ConfigurationValues.getTarget());
NativeImageGenerator.registerReplacements(debug, featureHandler, runtimeConfig, runtimeConfig.getProviders(), false, true);
featureHandler.forEachGraalFeature(feature -> feature.registerCodeObserver(runtimeConfig));
Suites suites = NativeImageGenerator.createSuites(featureHandler, runtimeConfig, runtimeConfig.getSnippetReflection(), false);
LIRSuites lirSuites = NativeImageGenerator.createLIRSuites(featureHandler, runtimeConfig.getProviders(), false);
Suites firstTierSuites = NativeImageGenerator.createFirstTierSuites(featureHandler, runtimeConfig, runtimeConfig.getSnippetReflection(), false);
LIRSuites firstTierLirSuites = NativeImageGenerator.createFirstTierLIRSuites(featureHandler, runtimeConfig.getProviders(), false);
GraalSupport.setRuntimeConfig(runtimeConfig, suites, lirSuites, firstTierSuites, firstTierLirSuites);
NodeClass<?>[] snippetNodeClasses = ((SubstrateReplacements) runtimeProviders.getReplacements()).getSnippetNodeClasses();
for (NodeClass<?> nodeClass : snippetNodeClasses) {
config.getMetaAccess().lookupJavaType(nodeClass.getClazz()).registerAsAllocated(null);
}
/* Initialize configuration with reasonable default values. */
graphBuilderConfig = GraphBuilderConfiguration.getDefault(hostedProviders.getGraphBuilderPlugins()).withBytecodeExceptionMode(BytecodeExceptionMode.ExplicitOnly);
includeCalleePredicate = GraalFeature::defaultIncludeCallee;
optimisticOpts = OptimisticOptimizations.ALL.remove(OptimisticOptimizations.Optimization.UseLoopLimitChecks);
methods = new LinkedHashMap<>();
graphEncoder = new GraphEncoder(ConfigurationValues.getTarget().arch);
/*
* Ensure that all snippet methods have their SubstrateMethod object created by the object
* replacer, to avoid corner cases later when writing the native image.
*/
for (ResolvedJavaMethod method : ((SubstrateReplacements) runtimeProviders.getReplacements()).getSnippetMethods()) {
objectReplacer.apply(method);
}
}
use of com.oracle.svm.core.graal.code.SubstrateBackend in project graal by oracle.
the class NativeImageGenerator method createFirstTierSuites.
public static Suites createFirstTierSuites(FeatureHandler featureHandler, RuntimeConfiguration runtimeConfig, SnippetReflectionProvider snippetReflection, boolean hosted) {
SubstrateBackend backend = runtimeConfig.getBackendForNormalMethod();
Suites suites;
if (hosted) {
suites = GraalConfiguration.hostedInstance().createFirstTierSuites(HostedOptionValues.singleton(), hosted);
} else {
suites = GraalConfiguration.runtimeInstance().createFirstTierSuites(RuntimeOptionValues.singleton(), hosted);
}
return modifySuites(backend, suites, featureHandler, runtimeConfig, snippetReflection, hosted, true);
}
use of com.oracle.svm.core.graal.code.SubstrateBackend 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);
}
}
}
use of com.oracle.svm.core.graal.code.SubstrateBackend in project graal by oracle.
the class SubstrateAMD64Feature method afterRegistration.
@Override
public void afterRegistration(AfterRegistrationAccess access) {
ImageSingletons.add(SubstrateRegisterConfigFactory.class, new SubstrateRegisterConfigFactory() {
@Override
public RegisterConfig newRegisterFactory(ConfigKind config, MetaAccessProvider metaAccess, TargetDescription target, Boolean preserveFramePointer) {
return new SubstrateAMD64RegisterConfig(config, metaAccess, target, preserveFramePointer);
}
});
ImageSingletons.add(ReservedRegisters.class, new AMD64ReservedRegisters());
if (!SubstrateOptions.useLLVMBackend()) {
AMD64CalleeSavedRegisters.createAndRegister();
ImageSingletons.add(SubstrateBackendFactory.class, new SubstrateBackendFactory() {
@Override
public SubstrateBackend newBackend(Providers newProviders) {
return new SubstrateAMD64Backend(newProviders);
}
});
ImageSingletons.add(SubstrateLoweringProviderFactory.class, new SubstrateLoweringProviderFactory() {
@Override
public DefaultJavaLoweringProvider newLoweringProvider(MetaAccessProvider metaAccess, ForeignCallsProvider foreignCalls, PlatformConfigurationProvider platformConfig, MetaAccessExtensionProvider metaAccessExtensionProvider, TargetDescription target) {
return new SubstrateAMD64LoweringProvider(metaAccess, foreignCalls, platformConfig, metaAccessExtensionProvider, target);
}
});
ImageSingletons.add(TargetGraphBuilderPlugins.class, new AMD64GraphBuilderPlugins());
ImageSingletons.add(SubstrateSuitesCreatorProvider.class, new SubstrateAMD64SuitesCreatorProvider());
}
}
Aggregations