Skip to content
New issue

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

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

Already on GitHub? # to your account

[GR-56112] Add detection of System.getProperty("java.home") calls #10030

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

Conversation

graalvmbot
Copy link
Collaborator

In this PR we add a detection system for System.getProperty("java.home") calls that, if detected, prints a warning message and a recommendation of the proper binary usage. Also added a native-image option -H:+TrackJavaHomeAccess that additionally prints the locations of all the previously found System.getProperty("java.home") calls.

On a simple java.home collecting app:

public class JavaHomeCollector {
    public String s = System.getProperty("java.home");
    public static void main(String[] args) {
    	System.getProperty("java.home");

    	System.getProperty("java.home", "");
    	
    	JavaHomeCollector asdf = new JavaHomeCollector();
    }
}

the native-image output during analysis includes:

Build resources:
 - 23.03GB of memory (75.6% of 30.48GB system memory, determined at start)
 - 22 thread(s) (100.0% of 22 available processor(s), determined at start)
Warning: System.getProperty("java.home") called at JavaHomeCollector.main(JavaHomeCollector.java:4)
Warning: System.getProperty("java.home") called at JavaHomeCollector.main(JavaHomeCollector.java:6)
Warning: System.getProperty("java.home") called at com.oracle.svm.core.code.FactoryMethodHolder.JavaHomeCollector_vvAEcUCjAm2lXGX7xB4Gi8(generated:0)
[2/8] Performing analysis...  [*****]                                                                    (4.2s @ 0.32GB)
    2,082 reachable types   (56.2% of    3,703 total)
    1,842 reachable fields  (37.6% of    4,895 total)
    8,734 reachable methods (34.0% of   25,699 total)

and after creating the image:

Security report:
 - Binary includes Java deserialization.
 - Use '--enable-sbom' to assemble a Software Bill of Materials (SBOM).
------------------------------------------------------------------------------------------------------------------------
Recommendations:
 G1GC: Use the G1 GC ('--gc=G1') for improved latency and throughput.
 PGO:  Use Profile-Guided Optimizations ('--pgo') for improved throughput.
 HOME: Set java.home when running the binary with '-Djava.home=<path>'.
 HEAP: Set max heap for improved and more predictable memory usage.
 CPU:  Enable more CPU features with '-march=native' for improved performance.
------------------------------------------------------------------------------------------------------------------------
                       1.3s (5.7% of total time) in 191 GCs | Peak RSS: 1.21GB | CPU load: 13.90
------------------------------------------------------------------------------------------------------------------------

On a more complex project, such as when building a native-image layer of the library artifact com.sun.mail:jakarta.mail:2.0.1, we can see a more detailed output message during analysis:

Build resources:
 - 9.00GB of memory (29.5% of 30.48GB system memory, determined at start)
 - 22 thread(s) (100.0% of 22 available processor(s), determined at start)
Warning: System.getProperty("java.home") called at jakarta.mail.Session$1.run(Session.java:220)
Warning: System.getProperty("java.home") called at java.util.logging.LogManager.getConfigurationFileName(LogManager.java:1391)
Warning: System.getProperty("java.home") called at jakarta.activation.MailcapCommandMap$1.run(MailcapCommandMap.java:125)
Warning: System.getProperty("java.home") called at java.awt.Toolkit$1.run(Toolkit.java:430)
Warning: System.getProperty("java.home") called at sun.security.util.DomainName$Rules$1.run(DomainName.java:212)
Warning: System.getProperty("java.home") called at jakarta.activation.MimetypesFileTypeMap$1.run(MimetypesFileTypeMap.java:77)
Warning: System.getProperty("java.home") called at sun.font.SunFontManager$1.run(SunFontManager.java:282)
Warning: System.getProperty("java.home") called at sun.awt.FontConfiguration.findFontConfigFile(FontConfiguration.java:178)
Warning: System.getProperty("java.home") called at sun.font.FcFontConfiguration.init(FcFontConfiguration.java:118)
Warning: System.getProperty("java.home") called at com.sun.naming.internal.VersionHelper.lambda$getJavaHomeConfStream$4(VersionHelper.java:224)
[2/8] Performing analysis...  [*************]                                                           (17.7s @ 1.60GB)
    9,643 reachable types   (67.5% of   14,282 total)
   35,411 reachable fields  (97.8% of   36,207 total)
   54,977 reachable methods (42.8% of  128,314 total)

The recommendation message after creating the image stays the same.

Added a native-image option -H:+TrackJavaHomeAccess that currently prints all System.getProperty("java.home") calls found during analysis.
# for free to join this conversation on GitHub. Already have an account? # 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