Skip to content

Commit

Permalink
[GR-39406] Add class initialization strategy that allows all classes …
Browse files Browse the repository at this point in the history
…to be used at image build time.

PullRequest: graal/12121
  • Loading branch information
Christian Wimmer committed Jul 2, 2022
2 parents b62f37f + d90833a commit faeaf3d
Show file tree
Hide file tree
Showing 18 changed files with 676 additions and 429 deletions.
1 change: 1 addition & 0 deletions substratevm/mx.substratevm/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,7 @@
"com.oracle.truffle.api.instrumentation.TruffleInstrument.Provider",
"com.oracle.svm.hosted.agent.NativeImageBytecodeInstrumentationAgentExtension",
"com.oracle.svm.hosted.NativeImageClassLoaderPostProcessing",
"java.util.spi.ResourceBundleControlProvider",
],
"requiresConcealed": {
"jdk.internal.vm.ci": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public void afterRegistration(AfterRegistrationAccess access) {
* certificate files while generating X509Certificates.
*/
rci.initializeAtBuildTime("org.jcp.xml.dsig.internal.dom.XMLDSigRI", "Required for TrustStoreManager");
rci.initializeAtBuildTime("org.jcp.xml.dsig.internal.dom.XMLDSigRI$ProviderService", "Required for TrustStoreManager");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ public void duringSetup(DuringSetupAccess access) {
access.registerObjectReplacer(this::replaceHostedPlatformManagedObject);

RuntimeClassInitialization.initializeAtBuildTime("com.sun.jmx.mbeanserver.DefaultMXBeanMappingFactory");
RuntimeClassInitialization.initializeAtBuildTime("com.sun.jmx.mbeanserver.DefaultMXBeanMappingFactory$Mappings");
RuntimeClassInitialization.initializeAtBuildTime("com.sun.jmx.mbeanserver.DefaultMXBeanMappingFactory$IdentityMapping");
RuntimeClassInitialization.initializeAtBuildTime("com.sun.jmx.mbeanserver.DescriptorCache");
RuntimeClassInitialization.initializeAtBuildTime("com.sun.jmx.remote.util.ClassLogger");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@
*/
package com.oracle.svm.hosted;

import static com.oracle.graal.pointsto.api.PointstoOptions.UseExperimentalReachabilityAnalysis;
import static com.oracle.svm.hosted.NativeImageOptions.DiagnosticsDir;
import static com.oracle.svm.hosted.NativeImageOptions.DiagnosticsMode;
import static org.graalvm.compiler.hotspot.JVMCIVersionCheck.OPEN_LABSJDK_RELEASE_URL_PATTERN;
import static com.oracle.graal.pointsto.api.PointstoOptions.UseExperimentalReachabilityAnalysis;
import static org.graalvm.compiler.replacements.StandardGraphBuilderPlugins.registerInvocationPlugins;

import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.ref.Reference;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
Expand All @@ -56,18 +57,6 @@
import java.util.function.BooleanSupplier;
import java.util.stream.Collectors;

import com.oracle.graal.pointsto.ObjectScanningObserver;
import com.oracle.graal.pointsto.PointsToAnalysis;
import com.oracle.graal.pointsto.flow.MethodTypeFlowBuilder;
import com.oracle.graal.pointsto.meta.AnalysisFactory;
import com.oracle.graal.pointsto.meta.PointsToAnalysisFactory;
import com.oracle.graal.pointsto.meta.PointsToAnalysisMethod;
import com.oracle.graal.reachability.MethodSummaryProvider;
import com.oracle.graal.reachability.ReachabilityAnalysisFactory;
import com.oracle.graal.reachability.ReachabilityObjectScanner;
import com.oracle.svm.hosted.analysis.NativeImageReachabilityAnalysisEngine;
import com.oracle.graal.pointsto.util.TimerCollection;
import com.oracle.svm.util.AnnotationExtracter;
import org.graalvm.collections.EconomicSet;
import org.graalvm.collections.Pair;
import org.graalvm.compiler.api.replacements.Fold;
Expand Down Expand Up @@ -143,28 +132,38 @@
import com.oracle.graal.pointsto.AnalysisObjectScanningObserver;
import com.oracle.graal.pointsto.AnalysisPolicy;
import com.oracle.graal.pointsto.BigBang;
import com.oracle.graal.pointsto.typestate.DefaultAnalysisPolicy;
import com.oracle.graal.pointsto.ObjectScanningObserver;
import com.oracle.graal.pointsto.PointsToAnalysis;
import com.oracle.graal.pointsto.api.PointstoOptions;
import com.oracle.graal.pointsto.constraints.UnsupportedFeatureException;
import com.oracle.graal.pointsto.flow.FormalParamTypeFlow;
import com.oracle.graal.pointsto.flow.MethodTypeFlowBuilder;
import com.oracle.graal.pointsto.flow.TypeFlow;
import com.oracle.graal.pointsto.flow.context.bytecode.BytecodeSensitiveAnalysisPolicy;
import com.oracle.graal.pointsto.heap.HeapSnapshotVerifier;
import com.oracle.graal.pointsto.heap.ImageHeap;
import com.oracle.graal.pointsto.heap.ImageHeapScanner;
import com.oracle.graal.pointsto.infrastructure.SubstitutionProcessor;
import com.oracle.graal.pointsto.infrastructure.WrappedJavaMethod;
import com.oracle.graal.pointsto.meta.AnalysisFactory;
import com.oracle.graal.pointsto.meta.AnalysisField;
import com.oracle.graal.pointsto.meta.AnalysisMetaAccess;
import com.oracle.graal.pointsto.meta.AnalysisMethod;
import com.oracle.graal.pointsto.meta.AnalysisType;
import com.oracle.graal.pointsto.meta.AnalysisUniverse;
import com.oracle.graal.pointsto.meta.HostedProviders;
import com.oracle.graal.pointsto.meta.PointsToAnalysisFactory;
import com.oracle.graal.pointsto.meta.PointsToAnalysisMethod;
import com.oracle.graal.pointsto.reports.AnalysisReporter;
import com.oracle.graal.pointsto.typestate.DefaultAnalysisPolicy;
import com.oracle.graal.pointsto.typestate.TypeState;
import com.oracle.graal.pointsto.util.AnalysisError;
import com.oracle.graal.pointsto.util.GraalAccess;
import com.oracle.graal.pointsto.util.Timer.StopTimer;
import com.oracle.graal.pointsto.util.TimerCollection;
import com.oracle.graal.reachability.MethodSummaryProvider;
import com.oracle.graal.reachability.ReachabilityAnalysisFactory;
import com.oracle.graal.reachability.ReachabilityObjectScanner;
import com.oracle.svm.core.BuildArtifacts;
import com.oracle.svm.core.BuildArtifacts.ArtifactType;
import com.oracle.svm.core.BuildPhaseProvider;
Expand Down Expand Up @@ -241,6 +240,7 @@
import com.oracle.svm.hosted.ameta.AnalysisConstantReflectionProvider;
import com.oracle.svm.hosted.analysis.Inflation;
import com.oracle.svm.hosted.analysis.NativeImagePointsToAnalysis;
import com.oracle.svm.hosted.analysis.NativeImageReachabilityAnalysisEngine;
import com.oracle.svm.hosted.analysis.SVMAnalysisMetaAccess;
import com.oracle.svm.hosted.analysis.SubstrateUnsupportedFeatures;
import com.oracle.svm.hosted.annotation.AnnotationSupport;
Expand All @@ -253,7 +253,6 @@
import com.oracle.svm.hosted.cenum.CEnumCallWrapperSubstitutionProcessor;
import com.oracle.svm.hosted.classinitialization.ClassInitializationFeature;
import com.oracle.svm.hosted.classinitialization.ClassInitializationSupport;
import com.oracle.svm.hosted.classinitialization.ConfigurableClassInitialization;
import com.oracle.svm.hosted.code.CEntryPointCallStubSupport;
import com.oracle.svm.hosted.code.CEntryPointData;
import com.oracle.svm.hosted.code.CFunctionSubstitutionProcessor;
Expand Down Expand Up @@ -293,6 +292,8 @@
import com.oracle.svm.hosted.substitute.AnnotationSubstitutionProcessor;
import com.oracle.svm.hosted.substitute.DeletedFieldsPlugin;
import com.oracle.svm.hosted.substitute.UnsafeAutomaticSubstitutionProcessor;
import com.oracle.svm.util.AnnotationExtracter;
import com.oracle.svm.util.ClassUtil;
import com.oracle.svm.util.ImageBuildStatistics;
import com.oracle.svm.util.ReflectionUtil;
import com.oracle.svm.util.ReflectionUtil.ReflectionUtilError;
Expand Down Expand Up @@ -828,7 +829,7 @@ private void setupNativeImage(OptionValues options, Map<Method, CEntryPointData>
ImageSingletons.add(ClassLoaderSupport.class, classLoaderSupport);
ImageSingletons.add(LinkAtBuildTimeSupport.class, new LinkAtBuildTimeSupport(loader, classLoaderSupport));

ClassInitializationSupport classInitializationSupport = new ConfigurableClassInitialization(originalMetaAccess, loader);
ClassInitializationSupport classInitializationSupport = ClassInitializationSupport.create(originalMetaAccess, loader);
ImageSingletons.add(RuntimeClassInitializationSupport.class, classInitializationSupport);
ClassInitializationFeature.processClassInitializationOptions(classInitializationSupport);

Expand Down Expand Up @@ -1603,7 +1604,7 @@ private void processNativeLibraryImports(NativeLibraries nativeLibs, MetaAccessP

for (Method method : loader.findAnnotatedMethods(CConstant.class)) {
if (LibCBase.isMethodProvidedInCurrentLibc(method)) {
classInitializationSupport.initializeAtBuildTime(method.getDeclaringClass(), "classes with " + CConstant.class.getSimpleName() + " annotations are always initialized");
initializeAtBuildTime(method.getDeclaringClass(), classInitializationSupport, CConstant.class);
nativeLibs.loadJavaMethod(metaAccess.lookupJavaMethod(method));
}
}
Expand All @@ -1614,38 +1615,38 @@ private void processNativeLibraryImports(NativeLibraries nativeLibs, MetaAccessP
}
for (Class<?> clazz : loader.findAnnotatedClasses(CStruct.class, false)) {
if (LibCBase.isTypeProvidedInCurrentLibc(clazz)) {
classInitializationSupport.initializeAtBuildTime(clazz, "classes annotated with " + CStruct.class.getSimpleName() + " are always initialized");
initializeAtBuildTime(clazz, classInitializationSupport, CStruct.class);
nativeLibs.loadJavaType(metaAccess.lookupJavaType(clazz));
}
}
for (Class<?> clazz : loader.findAnnotatedClasses(RawStructure.class, false)) {
if (LibCBase.isTypeProvidedInCurrentLibc(clazz)) {
classInitializationSupport.initializeAtBuildTime(clazz, "classes annotated with " + RawStructure.class.getSimpleName() + " are always initialized");
initializeAtBuildTime(clazz, classInitializationSupport, RawStructure.class);
nativeLibs.loadJavaType(metaAccess.lookupJavaType(clazz));
}
}
for (Class<?> clazz : loader.findAnnotatedClasses(CPointerTo.class, false)) {
if (LibCBase.isTypeProvidedInCurrentLibc(clazz)) {
classInitializationSupport.initializeAtBuildTime(clazz, "classes annotated with " + CPointerTo.class.getSimpleName() + " are always initialized");
initializeAtBuildTime(clazz, classInitializationSupport, CPointerTo.class);
nativeLibs.loadJavaType(metaAccess.lookupJavaType(clazz));
}
}
for (Class<?> clazz : loader.findAnnotatedClasses(RawPointerTo.class, false)) {
if (LibCBase.isTypeProvidedInCurrentLibc(clazz)) {
classInitializationSupport.initializeAtBuildTime(clazz, "classes annotated with " + RawPointerTo.class.getSimpleName() + " are always initialized");
initializeAtBuildTime(clazz, classInitializationSupport, RawPointerTo.class);
nativeLibs.loadJavaType(metaAccess.lookupJavaType(clazz));
}
}
for (Class<?> clazz : loader.findAnnotatedClasses(CEnum.class, false)) {
if (LibCBase.isTypeProvidedInCurrentLibc(clazz)) {
ResolvedJavaType type = metaAccess.lookupJavaType(clazz);
classInitializationSupport.initializeAtBuildTime(clazz, "classes annotated with " + CEnum.class.getSimpleName() + " are always initialized");
initializeAtBuildTime(clazz, classInitializationSupport, CEnum.class);
nativeLibs.loadJavaType(type);
}
}
for (Class<?> clazz : loader.findAnnotatedClasses(CContext.class, false)) {
if (LibCBase.isTypeProvidedInCurrentLibc(clazz)) {
classInitializationSupport.initializeAtBuildTime(clazz, "classes annotated with " + CContext.class.getSimpleName() + " are always initialized");
initializeAtBuildTime(clazz, classInitializationSupport, CContext.class);
}
}
nativeLibs.processCLibraryAnnotations(loader);
Expand All @@ -1654,6 +1655,12 @@ private void processNativeLibraryImports(NativeLibraries nativeLibs, MetaAccessP
nativeLibs.reportErrors();
}

private static void initializeAtBuildTime(Class<?> clazz, ClassInitializationSupport classInitializationSupport, Class<? extends Annotation> annotationForMessage) {
String message = "classes annotated with " + ClassUtil.getUnqualifiedName(annotationForMessage) + " are always initialized at image build time";
classInitializationSupport.initializeAtBuildTime(clazz, message);
classInitializationSupport.forceInitializeHosted(clazz, message, false);
}

public AbstractImage getBuiltImage() {
return image;
}
Expand Down
Loading

0 comments on commit faeaf3d

Please sign in to comment.