Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GR-54953] Option -H:Preserve=all that preserves all classes and reflection metadata from a module, a package, or a classpath entry. #10180

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

graalvmbot
Copy link
Collaborator

@graalvmbot graalvmbot commented Nov 28, 2024

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:

  1. -H:Preserve=all preserves all elements from the JDK, the classpath, and the module path
  2. -H:Preserve=module=<module> preserves all elements from a given module
  3. -H:Preserve=module=ALL-UNNAMED preserves all elements from all class-path entries
  4. -H:Preserve=package=<package> preserves all elements from a given package
  5. -H:Preserve=package=<package-wildcard> preserves all elements from packages captured by the wildcard. For example, -H:Preserve=package=my.app.*.
  6. -H:Preserve=path=<cp-entry> preserves all elements from a given class-path entry
  7. A combination of any of the previous uses, for example, -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 the native-image.properties files.

Usages

  1. Internal: We want to test the reflection implementation. Already useful as it found 5+ bugs and performance issues.
  2. Internal/Framework: Want to test that the JDK/Framework works no matter what the user registers for reflection.
  3. End User: i) Wants to obfuscate his library or make it standalone without providing reflection (especially interesting for AWT and JFX. ii) Wants to run his project and use an unsupported library. iii) Doesn't want to provide metadata for the test cases of his project.

Performance Impact of -H:Preserve=module=ALL-UNNAMED

  1. Binary Size grows between 2x-3x without JDK modules being included.
  2. Performance drops by roughly 10% in microservices wihtout PGO.
  3. Time to first response grows proportionally to the image size by 10%-30%.
  4. Max RSS is increased for a factor proportional to the image size (roughly 5%-10% of the image size).

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):

$ native-image HelloWorld -Ob -H:Preserve=all
$ du -h ./helloworld
  283M    ./helloworld
$ time ./helloworld
Hello, World!
________________________________________________________
Executed in   34.94 millis    fish           external
  usr time   13.05 millis    0.00 micros   13.05 millis
  sys time   22.27 millis  510.00 micros   21.75 millis

Dangers

  1. The whole community could use this option and make performance worse.
  2. The usage of this option will slow down reachability metadata adoption.

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.

@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Nov 28, 2024
@graalvmbot graalvmbot force-pushed the vj/GR-54953-include-all-for-reflection branch 4 times, most recently from ddbfdd6 to 8ca7704 Compare December 3, 2024 13:56
@vjovanov vjovanov changed the title [GR-54953] Options to include all metadata from module or classpath entry. [GR-54953] Options to include all metadata from module or classpath entry Dec 3, 2024
@graalvmbot graalvmbot force-pushed the vj/GR-54953-include-all-for-reflection branch from 8ca7704 to 1fcdae6 Compare December 9, 2024 12:38
@graalvmbot graalvmbot force-pushed the vj/GR-54953-include-all-for-reflection branch 2 times, most recently from b7393b2 to bb5696b Compare January 14, 2025 13:04
@graalvmbot graalvmbot force-pushed the vj/GR-54953-include-all-for-reflection branch 2 times, most recently from ea706f2 to f94accf Compare February 5, 2025 13:50
@graalvmbot graalvmbot force-pushed the vj/GR-54953-include-all-for-reflection branch 12 times, most recently from 3973d94 to a7fc90a Compare February 17, 2025 12:08
@graalvmbot graalvmbot changed the title [GR-54953] Options to include all metadata from module or classpath entry [GR-54953] Options to include all classes and reflection metadata from a module, a package, or a classpath entry. Feb 25, 2025
@graalvmbot graalvmbot force-pushed the vj/GR-54953-include-all-for-reflection branch from a7fc90a to cdb7fc9 Compare February 27, 2025 11:07
@graalvmbot graalvmbot changed the title [GR-54953] Options to include all classes and reflection metadata from a module, a package, or a classpath entry. [GR-54953] Option -H:Preserve that preserves all classes and reflection metadata from a module, a package, or a classpath entry. Feb 27, 2025
@graalvmbot graalvmbot force-pushed the vj/GR-54953-include-all-for-reflection branch 2 times, most recently from df76467 to 7fd0a2d Compare February 27, 2025 12:37
@graalvmbot graalvmbot changed the title [GR-54953] Option -H:Preserve that preserves all classes and reflection metadata from a module, a package, or a classpath entry. [GR-54953] Option -H:Preserve=all that preserves all classes and reflection metadata from a module, a package, or a classpath entry. Feb 27, 2025
@graalvmbot graalvmbot force-pushed the vj/GR-54953-include-all-for-reflection branch from 7fd0a2d to 691516d Compare February 27, 2025 19:39
@graalvmbot graalvmbot force-pushed the vj/GR-54953-include-all-for-reflection branch 13 times, most recently from 0b76e98 to 2ce932d Compare March 6, 2025 12:07
@graalvmbot graalvmbot force-pushed the vj/GR-54953-include-all-for-reflection branch from 2ce932d to 558f288 Compare March 7, 2025 15:10
The `-H:Preserve` flag preserves all 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:

1. -H:Preserve=all preserves all elements from the JDK and from the classpath
2. -H:Preserve=module=<module> preserves all elements from a given module
3. -H:Preserve=module=ALL-UNNAMED preserves all elements from the classpath
4. -H:Preserve=package=<package> preserves all elements from a given package
5. -H:Preserve=package=<package-wildcard> preserves all elements from packages captured by the wildcard. For example, -H:Preserve=package=my.app.*.
6. -H:Preserve=path=<cp-entry> preserves all elements from a given class-path entry
7. A combination of any of the previous uses, for example, -H:Preserve=path=<cp-entry>,module<module>
@graalvmbot graalvmbot force-pushed the vj/GR-54953-include-all-for-reflection branch from 558f288 to 7c04e39 Compare March 7, 2025 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCA Verified All contributors have signed the Oracle Contributor Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants