public class ServiceLoaderFeature extends Object implements org.graalvm.nativeimage.hosted.Feature
ServiceLoader
on Substrate VM.
Services are registered in the folder "META-INF/services/"
using files
whose name is the fully qualified service interface name. We do not know which services are going
to be used by a native image: The parameter of ServiceLoader.load(java.lang.Class<S>, java.lang.ClassLoader)
is often but not always
a compile-time constant that we can track. But we also cannot put all registered services into
the native image.
We therefore use the following heuristic: we add all service loader files and service
implementation classes when the service interfaces that are seen as reachable by the static
analysis.
Each used service implementation class is added for reflection (using
RuntimeReflection.register(Class[])
) and for reflective
instantiation (using RuntimeReflection.registerForReflectiveInstantiation(Class[])
).
For each service interface, a single service loader file is added as a resource to the image. The
single file combines all the individual files that can come from different .jar files.Modifier and Type | Class and Description |
---|---|
static class |
ServiceLoaderFeature.Options |
org.graalvm.nativeimage.hosted.Feature.AfterAnalysisAccess, org.graalvm.nativeimage.hosted.Feature.AfterCompilationAccess, org.graalvm.nativeimage.hosted.Feature.AfterHeapLayoutAccess, org.graalvm.nativeimage.hosted.Feature.AfterImageWriteAccess, org.graalvm.nativeimage.hosted.Feature.AfterRegistrationAccess, org.graalvm.nativeimage.hosted.Feature.BeforeAnalysisAccess, org.graalvm.nativeimage.hosted.Feature.BeforeCompilationAccess, org.graalvm.nativeimage.hosted.Feature.BeforeImageWriteAccess, org.graalvm.nativeimage.hosted.Feature.CompilationAccess, org.graalvm.nativeimage.hosted.Feature.DuringAnalysisAccess, org.graalvm.nativeimage.hosted.Feature.DuringSetupAccess, org.graalvm.nativeimage.hosted.Feature.FeatureAccess, org.graalvm.nativeimage.hosted.Feature.IsInConfigurationAccess, org.graalvm.nativeimage.hosted.Feature.OnAnalysisExitAccess, org.graalvm.nativeimage.hosted.Feature.QueryReachabilityAccess
Constructor and Description |
---|
ServiceLoaderFeature() |
Modifier and Type | Method and Description |
---|---|
void |
afterRegistration(org.graalvm.nativeimage.hosted.Feature.AfterRegistrationAccess access) |
void |
beforeAnalysis(org.graalvm.nativeimage.hosted.Feature.BeforeAnalysisAccess access) |
void |
duringAnalysis(org.graalvm.nativeimage.hosted.Feature.DuringAnalysisAccess a) |
boolean |
isInConfiguration(org.graalvm.nativeimage.hosted.Feature.IsInConfigurationAccess access) |
public boolean isInConfiguration(org.graalvm.nativeimage.hosted.Feature.IsInConfigurationAccess access)
isInConfiguration
in interface org.graalvm.nativeimage.hosted.Feature
public void afterRegistration(org.graalvm.nativeimage.hosted.Feature.AfterRegistrationAccess access)
afterRegistration
in interface org.graalvm.nativeimage.hosted.Feature
public void beforeAnalysis(org.graalvm.nativeimage.hosted.Feature.BeforeAnalysisAccess access)
beforeAnalysis
in interface org.graalvm.nativeimage.hosted.Feature
public void duringAnalysis(org.graalvm.nativeimage.hosted.Feature.DuringAnalysisAccess a)
duringAnalysis
in interface org.graalvm.nativeimage.hosted.Feature