Skip to content

[GR-57253] Add dynamic call usage detection #10176

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

Closed
wants to merge 1 commit into from

Conversation

graalvmbot
Copy link
Collaborator

@graalvmbot graalvmbot commented Nov 28, 2024

In this PR we add a new phase in analysis that detects calls that might require metadata and serializes them and their source location. The phase is enabled by adding the -H:TrackMethodsRequiringMetadata=<jar-path> option when running native-image. The phase detects calls only in the base project with the provided source jar path and not in its dependencies. Note that you can track metadata requiring call usage in multiple jars by providing multiple paths separated by commas (-H:TrackMethodsRequiringMetadata=<jar-path1,jar-path2,...>). If any calls are detected, their source locations are serialized in <jar-name>_method_usage.json.
When building a native-image layer of the library artifact org.slf4j:slf4j-api:2.0.16, the native-image output includes:

[2/8] Performing analysis...  [*************]                                                           (12.0s @ 0.66GB)
    5,925 reachable types   (60.7% of    9,760 total)
   17,569 reachable fields  (95.7% of   18,367 total)
   29,971 reachable methods (35.6% of   84,249 total)
    2,029 types,    17 fields, and   511 methods registered for reflection
       61 types,    61 fields, and    55 methods registered for JNI access
        4 native libraries: dl, pthread, rt, z
[3/8] Building universe...                                                                               (2.7s @ 1.13GB)
Dynamic method usage detected in /home/jovan/.m2/repository/org/slf4j/slf4j-api/2.0.16/slf4j-api-2.0.16.jar:
    Reflection calls detected:
        java.lang.Class#getConstructor:
            at org.slf4j.LoggerFactory.loadExplicitlySpecified(LoggerFactory.java:227)
        java.lang.Class#getMethod:
            at org.slf4j.helpers.SubstituteLogger.isDelegateEventAware(SubstituteLogger.java:467)
        java.lang.ClassLoader#loadClass:
            at org.slf4j.LoggerFactory.loadExplicitlySpecified(LoggerFactory.java:226)
        java.lang.reflect.Constructor#newInstance:
            at org.slf4j.LoggerFactory.loadExplicitlySpecified(LoggerFactory.java:228)
        java.lang.reflect.Method#invoke:
            at org.slf4j.helpers.SubstituteLogger.log(SubstituteLogger.java:478)
    Resource calls detected:
        java.lang.ClassLoader#getResources:
            at org.slf4j.LoggerFactory.findPossibleStaticLoggerBinderPathSet(LoggerFactory.java:269)
[4/8] Parsing methods...      [**]                                                                       (3.5s @ 1.45GB)

while the generated slf4j-api-2.0.16_method_usage.json looks like this:

{
  "reflection": {
    "java.lang.Class#getConstructor": [
      "org.slf4j.LoggerFactory.loadExplicitlySpecified(LoggerFactory.java:227)"
    ],
    "java.lang.Class#getMethod": [
      "org.slf4j.helpers.SubstituteLogger.isDelegateEventAware(SubstituteLogger.java:467)"
    ],
    "java.lang.ClassLoader#loadClass": [
      "org.slf4j.LoggerFactory.loadExplicitlySpecified(LoggerFactory.java:226)"
    ],
    "java.lang.reflect.Constructor#newInstance": [
      "org.slf4j.LoggerFactory.loadExplicitlySpecified(LoggerFactory.java:228)"
    ],
    "java.lang.reflect.Method#invoke": [
      "org.slf4j.helpers.SubstituteLogger.log(SubstituteLogger.java:478)"
    ]
  },
  "resource": {
    "java.lang.ClassLoader#getResources": [
      "org.slf4j.LoggerFactory.findPossibleStaticLoggerBinderPathSet(LoggerFactory.java:269)"
    ]
  }
}

@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Nov 28, 2024
@zakkak
Copy link
Collaborator

zakkak commented Dec 9, 2024

Hello, this is an interesting addition. Could you please mirror the internal description as well? Thank you.

@graalvmbot graalvmbot force-pushed the jvukicev/GR-57253 branch 3 times, most recently from 0205389 to 47afe25 Compare December 23, 2024 08:32
@graalvmbot graalvmbot changed the title [GR-57253] Add reflection call detection [GR-57253] Add dynamic call usage detection Dec 23, 2024
@zakkak
Copy link
Collaborator

zakkak commented Jan 7, 2025

Hello, this is an interesting addition. Could you please mirror the internal description as well? Thank you.

@jormundur00 ^^

@graalvmbot graalvmbot force-pushed the jvukicev/GR-57253 branch 4 times, most recently from 5e0c7f3 to 273bc66 Compare January 31, 2025 11:02
@graalvmbot graalvmbot force-pushed the jvukicev/GR-57253 branch 4 times, most recently from 7308440 to 416d017 Compare April 11, 2025 10:34
@graalvmbot graalvmbot force-pushed the jvukicev/GR-57253 branch 4 times, most recently from 4819c7f to 5bdb431 Compare April 15, 2025 13:42
@graalvmbot graalvmbot force-pushed the jvukicev/GR-57253 branch 6 times, most recently from 5f82ac4 to efdd5ab Compare May 13, 2025 07:02
@graalvmbot graalvmbot force-pushed the jvukicev/GR-57253 branch 3 times, most recently from 601b657 to e079a0d Compare May 15, 2025 10:52
@graalvmbot graalvmbot force-pushed the jvukicev/GR-57253 branch 8 times, most recently from 4563696 to 8afdd04 Compare May 20, 2025 07:21
@graalvmbot graalvmbot force-pushed the jvukicev/GR-57253 branch from 8afdd04 to a9fdf1c Compare May 20, 2025 15:01
@graalvmbot graalvmbot closed this May 22, 2025
@graalvmbot graalvmbot deleted the jvukicev/GR-57253 branch May 22, 2025 02:11
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.

3 participants