[GR-54953] Option -H:Preserve=all that preserves all classes and reflection metadata from a module, a package, or a classpath entry. #10180
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduces a flag
-H:Preserve
that preserves all classes, resources and reflection metadata from module, class-path entry, or a package in the image. This will allow users to more easily support third-party libraries and get more user-friendly experience with Native Image.The flag can be used in following ways:
-H:Preserve=all
preserves all elements from the JDK, the classpath, and the module path-H:Preserve=module=<module>
preserves all elements from a given module-H:Preserve=module=ALL-UNNAMED
preserves all elements from all class-path entries-H:Preserve=package=<package>
preserves all elements from a given package-H:Preserve=package=<package-wildcard>
preserves all elements from packages captured by the wildcard. For example,-H:Preserve=package=my.app.*
.-H:Preserve=path=<cp-entry>
preserves all elements from a given class-path entry-H:Preserve=path=<cp-entry>,module=<module>,package=<package>
-H:Preserve
is only allowed on the native-image command line and cannot be embedded in thenative-image.properties
files.Usages
Performance Impact of
-H:Preserve=module=ALL-UNNAMED
Performance Impact of
-H:Preserve=all
Performance impact is similar to
-H:Preserve=module=ALL-UNNAMED
, but the images are significantly larger."Hello, World!" on Linux with
-Ob
(JDK included):Dangers
Review
The entry point for review is the
SubstrateOptions
file where all the options are defined. Once the bugs are fixed, all reflection-related changes will be moved to a separate PR and back ported.