Interface Feature
public interface Feature
Features allow clients to intercept the native image generation and run custom initialization
code at various stages. All code within feature classes is executed during native image
generation, and never at run time.
Features have several advantages over static class initializers (which also run during native image generation):
- The different feature methods are called at different stages during native image generation, which gives clients control over when code is executed.
- Feature methods have an
accessparameter that allows callbacks into the native image generator. - Feature methods run when the
ImageSingletonsis already set up, which allows features to prepare data structures that are then used at run time by querying theImageSingletons.
Implementation classes must have a no-argument constructor, which is used to instantiate a singleton instance for each feature using reflection. The following features are included during native image generation:
- Features explicitly specified on the command line.
- Features referenced as
requiredby another included feature. Required features are added transitively, and initialization methods of required features are called after invoking the constructor andisInConfiguration(Feature.IsInConfigurationAccess)of the requiring features (unless the feature dependencies are cyclic).
- Since:
- 19.0
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceAccess methods available forafterAnalysis(Feature.AfterAnalysisAccess).static interfaceAccess methods available forafterCompilation(Feature.AfterCompilationAccess).static interfaceAccess methods available forafterHeapLayout(Feature.AfterHeapLayoutAccess).static interfaceAccess methods available forafterImageWrite(Feature.AfterImageWriteAccess).static interfaceAccess methods available forafterRegistration(Feature.AfterRegistrationAccess).static interfaceAccess methods available forbeforeAnalysis(Feature.BeforeAnalysisAccess).static interfaceAccess methods available forbeforeCompilation(Feature.BeforeCompilationAccess).static interfaceAccess methods available forbeforeHeapLayout(Feature.BeforeHeapLayoutAccess).static interfaceAccess methods available forbeforeImageWrite(Feature.BeforeImageWriteAccess).static interfaceAccess methods available forbeforeUniverseBuilding(Feature.BeforeUniverseBuildingAccess).static interfaceAccess methods available forbeforeCompilation(Feature.BeforeCompilationAccess)andafterCompilation(Feature.AfterCompilationAccess).static interfaceAccess methods available forduringAnalysis(Feature.DuringAnalysisAccess).static interfaceAccess methods available forduringSetup(Feature.DuringSetupAccess).static interfaceAccess methods that are available for all feature methods.static interfaceAccess methods available forisInConfiguration(Feature.IsInConfigurationAccess).static interfaceAccess methods available foronAnalysisExit(Feature.OnAnalysisExitAccess).static interfaceAccess reachability methods available forafterAnalysis(Feature.AfterAnalysisAccess)andduringAnalysis(Feature.DuringAnalysisAccess). -
Method Summary
Modifier and TypeMethodDescriptiondefault voidHandler for initializations after analysis and before universe creation.default voidHandler for initializations after compilation, i.e., before the native image is written.default voidHandler for initializations after the native image heap and code layout.default voidHandler for altering the image (or shared object) that the linker command produced.default voidHandler for initializations after all features have been registered and all options have been parsed; but before any initializations for the static analysis have happened.default voidHandler for initializations before the static analysis.default voidHandler for initializations before compilation.default voidHandler for initializations before the native image heap and code layout.default voidHandler for altering the linker command after the native image has been built and before it is written.default voidHandler for code that needs to run before universe building, but after hosted meta-access has been created.default voidcleanup()Handler for cleanup.default voidHandler for performing operations during the static analysis.default voidduringSetup(Feature.DuringSetupAccess access) Handler for initializations at startup time.default StringA short description of the feature (e.g., "Enables Truffle support").Returns the list of features that this feature depends on.default StringgetURL()A URL to documentation or the sources of the feature.default booleanThis method is called immediately after the constructor, to check whether the feature is part of the configuration or not.default voidHandler for code that needs to run after the analysis, even if an error has occurred, e.g., like reporting code.
-
Method Details
-
getURL
A URL to documentation or the sources of the feature. The URL will be used as a link for the feature in the build output (if supported by the user's terminal).- Since:
- 22.2
-
getDescription
A short description of the feature (e.g., "Enables Truffle support"). The description is displayed to users as part of the build output.- Since:
- 22.2
-
isInConfiguration
This method is called immediately after the constructor, to check whether the feature is part of the configuration or not. If this method returns false, the feature is not included in the list of features and no other methods are called (in particular, therequired featuresare not processed).- Parameters:
access- The supported operations that the feature can perform at this time- Since:
- 19.0
-
getRequiredFeatures
-
afterRegistration
Handler for initializations after all features have been registered and all options have been parsed; but before any initializations for the static analysis have happened.- Parameters:
access- The supported operations that the feature can perform at this time- Since:
- 19.0
-
duringSetup
Handler for initializations at startup time. It allows customization of the static analysis setup.- Parameters:
access- The supported operations that the feature can perform at this time- Since:
- 19.0
-
beforeAnalysis
Handler for initializations before the static analysis.- Parameters:
access- The supported operations that the feature can perform at this time- Since:
- 19.0
-
duringAnalysis
Handler for performing operations during the static analysis. This handler is called after analysis is complete. So all analysis meta data is available. If the handler performs changes, e.g., makes new types or methods reachable, it needs to callFeature.DuringAnalysisAccess.requireAnalysisIteration(). This triggers a new iteration: analysis is performed again and the handler is called again.- Parameters:
access- The supported operations that the feature can perform at this time- Since:
- 19.0
-
afterAnalysis
Handler for initializations after analysis and before universe creation.- Parameters:
access- The supported operations that the feature can perform at this time- Since:
- 19.0
-
onAnalysisExit
Handler for code that needs to run after the analysis, even if an error has occurred, e.g., like reporting code.- Parameters:
access- The supported operations that the feature can perform at this time- Since:
- 19.0
-
beforeUniverseBuilding
Handler for code that needs to run before universe building, but after hosted meta-access has been created.- Parameters:
access- The supported operations that the feature can perform at this time- Since:
- 21.1
-
beforeCompilation
Handler for initializations before compilation.- Parameters:
access- The supported operations that the feature can perform at this time- Since:
- 19.0
-
afterCompilation
Handler for initializations after compilation, i.e., before the native image is written.- Parameters:
access- The supported operations that the feature can perform at this time- Since:
- 19.0
-
beforeHeapLayout
Handler for initializations before the native image heap and code layout.- Parameters:
access- The supported operations that the feature can perform at this time- Since:
- 23.2
-
afterHeapLayout
Handler for initializations after the native image heap and code layout. Objects and methods have their offsets assigned. At this point, no additional objects must be added to the native image heap, i.e., modifying object fields of native image objects that are part of the native image heap is not allowed at this point.- Parameters:
access- The supported operations that the feature can perform at this time- Since:
- 19.0
-
beforeImageWrite
Handler for altering the linker command after the native image has been built and before it is written.- Parameters:
access- The supported operations that the feature can perform at this time.- Since:
- 19.0
-
afterImageWrite
Handler for altering the image (or shared object) that the linker command produced.- Parameters:
access- The supported operations that the feature can perform at this time.- Since:
- 19.0
-
cleanup
default void cleanup()Handler for cleanup. Can be used to cleanup static data. This can avoid memory leaks if native image generation is done many times, e.g. during unit tests.Usually, overriding this method can be avoided by putting a configuration object into the
ImageSingletons.- Since:
- 19.0
-