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

[Native Image] GraalVM for JDK 24 ignores manifest entry Enable-Native-Access #10008

Closed
1 task done
zakkak opened this issue Nov 1, 2024 · 0 comments · Fixed by #10009
Closed
1 task done

[Native Image] GraalVM for JDK 24 ignores manifest entry Enable-Native-Access #10008

zakkak opened this issue Nov 1, 2024 · 0 comments · Fixed by #10009

Comments

@zakkak
Copy link
Collaborator

zakkak commented Nov 1, 2024

Describe the Issue

GraalVM for JDK 24 ignores manifest entry Enable-Native-Access when compiling to native image, resulting in warnings. According to JEP 472:

You can add Enable-Native-Access: ALL-UNNAMED to the manifest of an executable JAR file, i.e., a JAR file that is launched via java -jar. (The only supported value for the Enable-Native-Access manifest entry is ALL-UNNAMED; other values cause an exception to be thrown.)

I would expect native-image to detect this entry and not throw warnings.

Using the latest version of GraalVM can resolve many issues.

GraalVM Version

native-image 24 2025-03-18
GraalVM Runtime Environment GraalVM CE 24-dev+21.1 (build 24+21-jvmci-b01)
Substrate VM GraalVM CE 24-dev+21.1 (build 24+21, serial gc)

8a88c44

Operating System and Version

Linux fedora 6.11.5-300.fc41.x86_64

Build Command

$JAVA_HOME/bin/native-image --initialize-at-build-time=. -jar target/reproducer-1.0-SNAPSHOT.jar

Expected Behavior

Native build should build without any warnings.

Actual Behavior

Native build prints warnings:

WARNING: A restricted method in java.lang.System has been called
WARNING: java.lang.System::loadLibrary has been called by com.aayushatharva.brotli4j.Brotli4jLoader in an unnamed module (file:/home/zakkak/code/issue-reproducers/target/reproducer-1.0-SNAPSHOT.jar)
WARNING: Use --enable-native-access=ALL-UNNAMED to avoid a warning for callers in this module
WARNING: Restricted methods will be blocked in a future release unless native access is enabled

Steps to Reproduce

cd /tmp
git clone --branch 2024-11-01-jep472-manifest-ignored https://github.com/zakkak/issue-reproducers reproducers
cd reproducers
mvn package
# run in JVM (with no warnings)
$JAVA_HOME/bin/java \
  -jar target/reproducer-1.0-SNAPSHOT.jar
# generate native-image
$JAVA_HOME/bin/native-image \
  --no-fallback \
  --initialize-at-build-time=.  \
  -jar target/reproducer-1.0-SNAPSHOT.jar
# Build prints warning about native access

Additional Context

No response

Build Log Output and Error Messages

Build Log:
========================================================================================================================
GraalVM Native Image: Generating 'reproducer-1.0-SNAPSHOT' (executable)...
========================================================================================================================
[1/8] Initializing...                                                                                    (1.5s @ 0.14GB)
 Java version: 24+21, vendor version: GraalVM CE 24-dev+21.1
 Graal compiler: optimization level: 2, target machine: x86-64-v3
 C compiler: gcc (redhat, x86_64, 14.2.1)
 Garbage collector: Serial GC (max heap size: 80% of RAM)
 1 user-specific feature(s):
 - com.oracle.svm.thirdparty.gson.GsonFeature
------------------------------------------------------------------------------------------------------------------------
Build resources:
 - 26.49GB of memory (42.8% of 61.93GB system memory, determined at start)
 - 32 thread(s) (100.0% of 32 available processor(s), determined at start)
[2/8] Performing analysis...  [WARNING: A restricted method in java.lang.System has been called
WARNING: java.lang.System::loadLibrary has been called by com.aayushatharva.brotli4j.Brotli4jLoader in an unnamed module (file:/home/zakkak/code/issue-reproducers/target/reproducer-1.0-SNAPSHOT.jar)
WARNING: Use --enable-native-access=ALL-UNNAMED to avoid a warning for callers in this module
WARNING: Restricted methods will be blocked in a future release unless native access is enabled

****]                                                                     (2.1s @ 0.45GB)
    3,342 reachable types   (70.1% of    4,765 total)
    3,836 reachable fields  (42.9% of    8,952 total)
   15,604 reachable methods (44.1% of   35,401 total)
    1,034 types,     7 fields, and   140 methods registered for reflection
       57 types,    58 fields, and    52 methods registered for JNI access
        4 native libraries: dl, pthread, rt, z
[3/8] Building universe...                                                                               (0.6s @ 0.45GB)
[4/8] Parsing methods...      [*]                                                                        (0.4s @ 0.47GB)
[5/8] Inlining methods...     [***]                                                                      (0.2s @ 0.41GB)
[6/8] Compiling methods...    [**]                                                                       (2.5s @ 0.43GB)
[7/8] Laying out methods...   [*]                                                                        (0.7s @ 0.50GB)
[8/8] Creating image...       [*]                                                                        (0.7s @ 0.55GB)
   5.24MB (38.34%) for code area:     8,925 compilation units
   7.25MB (53.00%) for image heap:   95,542 objects and 55 resources
   1.19MB ( 8.67%) for other data
  13.68MB in total
------------------------------------------------------------------------------------------------------------------------
Top 10 origins of code area:                                Top 10 object types in image heap:
   3.91MB java.base                                            1.39MB byte[] for code metadata
 960.09kB svm.jar (Native Image)                               1.28MB byte[] for java.lang.String
 112.12kB java.logging                                       937.41kB java.lang.String
  75.44kB org.graalvm.nativeimage.base                       794.47kB java.lang.Class
  48.63kB jdk.proxy2                                         287.20kB com.oracle.svm.core.hub.DynamicHubCompanion
  38.81kB jdk.proxy1                                         275.33kB byte[] for general heap data
  26.34kB jdk.internal.vm.ci                                 261.28kB java.util.HashMap$Node
  20.08kB org.graalvm.collections                            208.43kB java.lang.Object[]
  11.92kB jdk.proxy3                                         186.57kB java.lang.String[]
   9.29kB jdk.graal.compiler                                 154.36kB byte[] for embedded resources
   2.31kB for 4 more packages                                  1.55MB for 953 more object types
------------------------------------------------------------------------------------------------------------------------
Recommendations:
 HEAP: Set max heap for improved and more predictable memory usage.
 CPU:  Enable more CPU features with '-march=native' for improved performance.
------------------------------------------------------------------------------------------------------------------------
                        0.4s (4.3% of total time) in 99 GCs | Peak RSS: 1.19GB | CPU load: 18.62
------------------------------------------------------------------------------------------------------------------------
Build artifacts:
 /home/zakkak/code/issue-reproducers/reproducer-1.0-SNAPSHOT (executable)
========================================================================================================================
Finished generating 'reproducer-1.0-SNAPSHOT' in 9.2s.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants