Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public enum ParsingReason {
PointsToAnalysis,
AOTCompilation,
JITCompilation,
EarlyClassInitializerAnalysis,
AutomaticUnsafeTransformation;

public boolean isForHosted() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ private void installRuntimeConfig(BeforeAnalysisAccessImpl config) {
final boolean supportsStubBasedPlugins = !SubstrateOptions.useLLVMBackend();

SubstrateTarget target = SubstrateTarget.singleton();
NativeImageGenerator.registerGraphBuilderPlugins(featureHandler, runtimeConfig, hostedProviders, config.getMetaAccess(), config.getUniverse(), config.getNativeLibraries(),
NativeImageGenerator.registerGraphBuilderPlugins(featureHandler, hostedProviders, config.getMetaAccess(), config.getNativeLibraries(),
config.getImageClassLoader(), ParsingReason.JITCompilation, ((Inflation) config.getBigBang()).getAnnotationSubstitutionProcessor(),
new SubstrateClassInitializationPlugin(config.getHostVM()), target, supportsStubBasedPlugins);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import static com.oracle.svm.hosted.NativeImageOptions.DiagnosticsDir;
import static com.oracle.svm.hosted.NativeImageOptions.DiagnosticsMode;
import static jdk.graal.compiler.hotspot.JVMCIVersionCheck.OPEN_LABSJDK_RELEASE_URL_PATTERN;
import static jdk.graal.compiler.replacements.StandardGraphBuilderPlugins.registerInvocationPlugins;

import java.io.IOException;
import java.lang.annotation.Annotation;
Expand Down Expand Up @@ -73,12 +72,11 @@
import org.graalvm.nativeimage.impl.APIDeprecationSupport;
import org.graalvm.nativeimage.impl.AnnotationExtractor;
import org.graalvm.nativeimage.impl.CConstantValueSupport;
import org.graalvm.nativeimage.impl.RuntimeStateSupport;
import org.graalvm.nativeimage.impl.RuntimeSerializationSupport;
import org.graalvm.nativeimage.impl.RuntimeStateSupport;
import org.graalvm.nativeimage.impl.SizeOfSupport;
import org.graalvm.nativeimage.impl.VMRuntimeSupport;
import org.graalvm.word.PointerBase;

import com.oracle.graal.pointsto.AnalysisObjectScanningObserver;
import com.oracle.graal.pointsto.AnalysisPolicy;
import com.oracle.graal.pointsto.BigBang;
Expand Down Expand Up @@ -166,15 +164,15 @@
import com.oracle.svm.core.jdk.ImageKindInfoSingleton;
import com.oracle.svm.core.jdk.ServiceCatalogSupport;
import com.oracle.svm.core.layeredimagesingleton.LoadedLayeredImageSingletonInfo;
import com.oracle.svm.guest.staging.meta.MethodOffset;
import com.oracle.svm.guest.staging.meta.MethodPointer;
import com.oracle.svm.core.snippets.SnippetRuntime;
import com.oracle.svm.core.util.ExitStatus;
import com.oracle.svm.core.util.InterruptImageBuilding;
import com.oracle.svm.core.util.UserError;
import com.oracle.svm.core.util.UserErrorSupportImpl;
import com.oracle.svm.guest.staging.config.SubstrateGuestLibC;
import com.oracle.svm.guest.staging.jdk.RuntimeSupport;
import com.oracle.svm.guest.staging.meta.MethodOffset;
import com.oracle.svm.guest.staging.meta.MethodPointer;
import com.oracle.svm.guest.staging.option.RuntimeOptionValues;
import com.oracle.svm.guest.staging.option.SharedLayerRuntimeOptionsValues;
import com.oracle.svm.guest.staging.util.LayeredHostedImageHeapMapCollector;
Expand Down Expand Up @@ -290,7 +288,6 @@
import com.oracle.svm.util.ImageBuildStatistics;
import com.oracle.svm.util.JVMCIReflectionUtil;
import com.oracle.svm.util.JVMCIRuntimeClassInitializationSupport;

import jdk.graal.compiler.api.replacements.SnippetReflectionProvider;
import jdk.graal.compiler.bytecode.BytecodeProvider;
import jdk.graal.compiler.bytecode.ResolvedJavaMethodBytecodeProvider;
Expand All @@ -314,6 +311,7 @@
import jdk.graal.compiler.nodes.graphbuilderconf.ClassInitializationPlugin;
import jdk.graal.compiler.nodes.graphbuilderconf.GeneratedPluginFactory;
import jdk.graal.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration;
import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugins;
import jdk.graal.compiler.nodes.graphbuilderconf.NodePlugin;
import jdk.graal.compiler.nodes.spi.CoreProviders;
import jdk.graal.compiler.nodes.spi.LoweringProvider;
Expand All @@ -339,6 +337,7 @@
import jdk.graal.compiler.phases.util.Providers;
import jdk.graal.compiler.printer.GraalDebugHandlersFactory;
import jdk.graal.compiler.replacements.NodeIntrinsificationProvider;
import jdk.graal.compiler.replacements.StandardGraphBuilderPlugins;
import jdk.graal.compiler.replacements.TargetGraphBuilderPlugins;
import jdk.graal.compiler.word.WordOperationPlugin;
import jdk.graal.compiler.word.WordTypes;
Expand Down Expand Up @@ -693,7 +692,8 @@ protected void doRun(Map<ResolvedJavaMethod, CEntryPointData> entryPoints, Resol
BuildPhaseProviderImpl.markHostedUniverseBuilt();
ClassInitializationSupport classInitializationSupport = bb.getHostVM().getClassInitializationSupport();
SubstratePlatformConfigurationProvider platformConfig = getPlatformConfig(hMetaAccess);
SubstrateReplacements analysisReplacements = (SubstrateReplacements) bb.getProviders(MethodVariant.ORIGINAL_METHOD).getReplacements();
HostedProviders analysisProviders = bb.getProviders(MethodVariant.ORIGINAL_METHOD);
SubstrateReplacements analysisReplacements = (SubstrateReplacements) analysisProviders.getReplacements();
runtimeConfiguration = new HostedRuntimeConfigurationBuilder(options, bb.getHostVM(), hUniverse, hMetaAccess,
analysisReplacements, classInitializationSupport, platformConfig,
bb.getSnippetReflectionProvider()).build();
Expand All @@ -702,10 +702,14 @@ protected void doRun(Map<ResolvedJavaMethod, CEntryPointData> entryPoints, Resol
hostedGraalConfiguration.setHostedUniverse(hUniverse);
}

registerGraphBuilderPlugins(featureHandler, runtimeConfiguration, (HostedProviders) runtimeConfiguration.getProviders(), bb.getMetaAccess(), aUniverse,
nativeLibraries, loader, ParsingReason.AOTCompilation, bb.getAnnotationSubstitutionProcessor(),
new SubstrateClassInitializationPlugin((SVMHost) aUniverse.hostVM()),
SubstrateTarget.singleton(), this.isStubBasedPluginsSupported());
ClassInitializationPlugin classInitializationPlugin = analysisProviders.getGraphBuilderPlugins().getClassInitializationPlugin();
GraphBuilderConfiguration.Plugins plugins = registerGraphBuilderPlugins(featureHandler, (HostedProviders) runtimeConfiguration.getProviders(), bb.getMetaAccess(), nativeLibraries,
loader, ParsingReason.AOTCompilation, bb.getAnnotationSubstitutionProcessor(), classInitializationPlugin, SubstrateTarget.singleton(), this
.isStubBasedPluginsSupported());
/* HostedRuntimeConfigurationBuilder creates all AOT backends with HostedProviders. */
for (SubstrateBackend backend : runtimeConfiguration.getBackends()) {
((HostedProviders) backend.getProviders()).setGraphBuilderPlugins(plugins);
}

if (NativeImageOptions.PrintUniverse.getValue()) {
hUniverse.printTypes();
Expand Down Expand Up @@ -1470,7 +1474,7 @@ public static void initializeBigBang(Inflation bb, OptionValues options, Feature
registerRootElements(bb);

SubstrateTarget target = SubstrateTarget.singleton();
NativeImageGenerator.registerGraphBuilderPlugins(featureHandler, null, analysisProviders, aMetaAccess, aUniverse, nativeLibraries, loader, ParsingReason.PointsToAnalysis,
NativeImageGenerator.registerGraphBuilderPlugins(featureHandler, analysisProviders, aMetaAccess, nativeLibraries, loader, ParsingReason.PointsToAnalysis,
bb.getAnnotationSubstitutionProcessor(), classInitializationPlugin, target, supportsStubBasedPlugins);
registerReplacements(debug, featureHandler, null, analysisProviders, true, initForeignCalls, new GraphEncoder(target.arch));

Expand Down Expand Up @@ -1674,29 +1678,28 @@ protected boolean isStubBasedPluginsSupported() {
return !SubstrateOptions.useLLVMBackend();
}

public static void registerGraphBuilderPlugins(FeatureHandler featureHandler, RuntimeConfiguration runtimeConfig, HostedProviders providers, AnalysisMetaAccess aMetaAccess,
AnalysisUniverse aUniverse, NativeLibraries nativeLibs, ImageClassLoader loader, ParsingReason reason,
AnnotationSubstitutionProcessor annotationSubstitutionProcessor, ClassInitializationPlugin classInitializationPlugin,
TargetDescription target, boolean supportsStubBasedPlugins) {
/**
* Registers plugins on the supplied providers and their replacements. Snippet reflection uses
* analysis metadata even when the supplied providers use hosted metadata for AOT compilation.
*
* @return the installed plugins, for reuse by additional backend provider bundles
*/
public static GraphBuilderConfiguration.Plugins registerGraphBuilderPlugins(FeatureHandler featureHandler, HostedProviders providers, AnalysisMetaAccess analysisMetaAccess,
NativeLibraries nativeLibs, ImageClassLoader loader, ParsingReason reason, AnnotationSubstitutionProcessor annotationSubstitutionProcessor,
ClassInitializationPlugin classInitializationPlugin, TargetDescription target, boolean supportsStubBasedPlugins) {
GraphBuilderConfiguration.Plugins plugins = new GraphBuilderConfiguration.Plugins(new SubstitutionInvocationPlugins(annotationSubstitutionProcessor));

HostedSnippetReflectionProvider hostedSnippetReflection = new HostedSnippetReflectionProvider(aUniverse.getHeapScanner(),
new SubstrateWordTypes(aMetaAccess, SubstrateTarget.getWordKind()));

WordOperationPlugin wordOperationPlugin = new SubstrateWordOperationPlugins(hostedSnippetReflection, providers.getConstantReflection(), providers.getWordTypes(),
providers.getPlatformConfigurationProvider().getBarrierSet());
AnalysisUniverse analysisUniverse = analysisMetaAccess.getUniverse();
HostedSnippetReflectionProvider analysisSnippetReflection = new HostedSnippetReflectionProvider(analysisUniverse.getHeapScanner(),
new SubstrateWordTypes(analysisMetaAccess, SubstrateTarget.getWordKind()));

SubstrateReplacements replacements = (SubstrateReplacements) providers.getReplacements();
plugins.appendInlineInvokePlugin(replacements);

if (reason.duringAnalysis()) {
MethodHandleAccessProvider methodHandleAccess = providers.getConstantReflection().getMethodHandleAccess();
NodePlugin methodHandlePlugin;
if (ForeignSupport.isAvailable()) {
methodHandlePlugin = ForeignHostedSupport.singleton().createHandleWithExceptionPlugin(methodHandleAccess);
} else {
methodHandlePlugin = new SVMMethodHandleWithExceptionPlugin(methodHandleAccess, false);
}
NodePlugin methodHandlePlugin = ForeignSupport.isAvailable() ? ForeignHostedSupport.singleton().createHandleWithExceptionPlugin(methodHandleAccess)
: new SVMMethodHandleWithExceptionPlugin(methodHandleAccess, false);
plugins.appendNodePlugin(methodHandlePlugin);
plugins.appendNodePlugin(new DevirtualizeInterfaceCallPlugin());
}
Expand All @@ -1709,6 +1712,8 @@ public static void registerGraphBuilderPlugins(FeatureHandler featureHandler, Ru
plugins.appendNodePlugin(new LocalizationFeature.CharsetNodePlugin());
plugins.appendNodePlugin(new DynamicHubPlugin());

WordOperationPlugin wordOperationPlugin = new SubstrateWordOperationPlugins(analysisSnippetReflection, providers.getConstantReflection(), providers.getWordTypes(),
providers.getPlatformConfigurationProvider().getBarrierSet());
plugins.appendInlineInvokePlugin(wordOperationPlugin);
plugins.appendTypePlugin(wordOperationPlugin);
plugins.appendNodePlugin(wordOperationPlugin);
Expand All @@ -1717,40 +1722,43 @@ public static void registerGraphBuilderPlugins(FeatureHandler featureHandler, Ru

featureHandler.forEachGraalFeature(feature -> feature.registerGraphBuilderPlugins(providers, plugins, reason));

NodeIntrinsificationProvider nodeIntrinsificationProvider = new NodeIntrinsificationProvider(providers.getMetaAccess(),
hostedSnippetReflection, providers.getForeignCalls(), providers.getWordTypes(), target);
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);
}
}
InvocationPlugins invocationPlugins = plugins.getInvocationPlugins();
registerGeneratedInvocationPlugins(loader, invocationPlugins, providers, analysisSnippetReflection, target);

final boolean useExactMathPlugins = SubstrateOptions.useLIRBackend();
registerInvocationPlugins(hostedSnippetReflection, plugins.getInvocationPlugins(), useExactMathPlugins, true, supportsStubBasedPlugins, true);
final boolean explicitUnsafeNullChecks = true;
final boolean enableAesPlugins = true;
StandardGraphBuilderPlugins.registerInvocationPlugins(analysisSnippetReflection, invocationPlugins, useExactMathPlugins, explicitUnsafeNullChecks, supportsStubBasedPlugins, enableAesPlugins);

OptionValues options = aUniverse.hostVM().options();
OptionValues options = analysisUniverse.hostVM().options();
ImageSingletons.lookup(TargetGraphBuilderPlugins.class).registerPlugins(plugins, options);

SubstrateGraphBuilderPlugins.registerInvocationPlugins(annotationSubstitutionProcessor,
loader,
plugins.getInvocationPlugins(),
reason,
supportsStubBasedPlugins);
SubstrateGraphBuilderPlugins.registerInvocationPlugins(annotationSubstitutionProcessor, loader, invocationPlugins, reason, supportsStubBasedPlugins);

featureHandler.forEachGraalFeature(feature -> feature.registerInvocationPlugins(providers, 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);
return plugins;
}

/**
* Discovers concrete {@link GeneratedPluginFactory} implementations and registers their invocation
* plugins. HotSpot-specific factories are excluded from Native Image registration.
*/
private static void registerGeneratedInvocationPlugins(ImageClassLoader loader, InvocationPlugins invocationPlugins, Providers providers,
SnippetReflectionProvider analysisSnippetReflection, TargetDescription target) {
NodeIntrinsificationProvider nodeIntrinsificationProvider = new NodeIntrinsificationProvider(providers.getMetaAccess(),
analysisSnippetReflection, providers.getForeignCalls(), providers.getWordTypes(), target);
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(invocationPlugins, nodeIntrinsificationProvider);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ public static void replaceWithThrowingAtRuntime(SharedBytecodeParser b, Class<?
* This method is currently not able to replace
* ExceptionSynthesizer.throwException(GraphBuilderContext, Method, String) because
* there are places where GraphBuilderContext.getMetaAccess() does not contain a
* UniverseMetaAccess (e.g. in case of ParsingReason.EarlyClassInitializerAnalysis). If
* UniverseMetaAccess (e.g. in case of ParsingReason.AutomaticUnsafeTransformation). If
* we can access the ParsingReason in here we will be able to get rid of throwException.
*/
var errorCtor = ReflectionUtil.lookupConstructor(throwableClass, String.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ private boolean processClassGetClassLoader(GraphBuilderContext b, ResolvedJavaMe
}

ClassLoader loader;
if (reason == ParsingReason.AutomaticUnsafeTransformation || reason == ParsingReason.EarlyClassInitializerAnalysis) {
if (reason == ParsingReason.AutomaticUnsafeTransformation) {
/*
* We are getting called before analysis, DynamicHubs are not available at this point.
* This is acceptable because those graphs will not be used by the analysis later.
Expand Down Expand Up @@ -750,7 +750,7 @@ private static boolean isAllowedConstant(Class<?> clazz) {
*/
@SuppressWarnings("unchecked")
private <T> T getIntrinsic(T element) {
if (reason == ParsingReason.AutomaticUnsafeTransformation || reason == ParsingReason.EarlyClassInitializerAnalysis) {
if (reason == ParsingReason.AutomaticUnsafeTransformation) {
/* We are analyzing the static initializers and should always intrinsify. */
return element;
}
Expand All @@ -772,7 +772,7 @@ private <T> T getIntrinsic(T element) {
* Same as {@link #getIntrinsic}, but returns a {@link JavaConstant}.
*/
private JavaConstant getIntrinsicConstant(GraphBuilderContext context, Object element) {
if (reason == ParsingReason.AutomaticUnsafeTransformation || reason == ParsingReason.EarlyClassInitializerAnalysis) {
if (reason == ParsingReason.AutomaticUnsafeTransformation) {
/* We are analyzing the static initializers and should always intrinsify. */
return context.getSnippetReflection().forObject(element);
}
Expand Down