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

Warnings about brotli in quarkus-netty when compiled with Mandrel 24.2 (JDK 24+15) or better #43538

Open
jerboaa opened this issue Sep 26, 2024 · 7 comments
Labels

Comments

@jerboaa
Copy link
Contributor

jerboaa commented Sep 26, 2024

Describe the bug

https://openjdk.org/jeps/472 got included with JDK 24. This means that JNI access will produce warnings when run with JDK 24 and certain restricted methods get called. This warning shows up with a Mandrel build using JDK 24+15 EA for example when compiling the getting started quickstart:

The warning produced by the JDK is:

WARNING: java.lang.System::loadLibrary has been called by com.aayushatharva.brotli4j.Brotli4jLoader in an unnamed module (file:/home/sgehwolf/Documents/openjdk/quarkus/quarkus-quickstarts/getting-started/target/getting-started-1.0.0-SNAPSHOT-native-image-source-jar/lib/com.aayushatharva.brotli4j.brotli4j-1.16.0.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

Example of an native image build where the warning happens:

[....]
[INFO] [io.quarkus.deployment.pkg.steps.NativeImageBuildRunner] /disk/graal/upstream-sources/graal/mandrel-build/bin/native-image -J-Dsun.nio.ch.maxUpdateArraySize=100 -J-Djava.util.logging.manager=org.jboss.logmanager.LogManager -J-Dlogging.initial-configurator.min-level=500 -J-Dvertx.logger-delegate-factory-class-name=io.quarkus.vertx.core.runtime.VertxLogDelegateFactory -J-Dvertx.disableDnsResolver=true -J-Dio.netty.leakDetection.level=DISABLED -J-Dio.netty.allocator.maxOrder=3 -J-Duser.language=en -J-Duser.country=US -J-Dfile.encoding=UTF-8 --features=io.quarkus.runner.Feature,io.quarkus.runtime.graal.DisableLoggingFeature -J--add-exports=java.security.jgss/sun.security.krb5=ALL-UNNAMED -J--add-exports=java.security.jgss/sun.security.jgss=ALL-UNNAMED -J--add-opens=java.base/java.text=ALL-UNNAMED -J--add-opens=java.base/java.io=ALL-UNNAMED -J--add-opens=java.base/java.lang.invoke=ALL-UNNAMED -J--add-opens=java.base/java.util=ALL-UNNAMED -H:+UnlockExperimentalVMOptions -H:BuildOutputJSONFile=getting-started-1.0.0-SNAPSHOT-runner-build-output-stats.json -H:-UnlockExperimentalVMOptions -H:+UnlockExperimentalVMOptions -H:+GenerateBuildArtifactsFile -H:-UnlockExperimentalVMOptions -H:+UnlockExperimentalVMOptions -H:+AllowFoldMethods -H:-UnlockExperimentalVMOptions -J-Djava.awt.headless=true --no-fallback --link-at-build-time -H:+UnlockExperimentalVMOptions -H:+ReportExceptionStackTraces -H:-UnlockExperimentalVMOptions -H:-AddAllCharsets --enable-url-protocols=http -H:NativeLinkerOption=-no-pie --enable-monitoring=heapdump -H:+UnlockExperimentalVMOptions -H:-UseServiceLoaderFeature -H:-UnlockExperimentalVMOptions -J--add-exports=org.graalvm.nativeimage/org.graalvm.nativeimage.impl=ALL-UNNAMED --exclude-config io\.netty\.netty-codec /META-INF/native-image/io\.netty/netty-codec/generated/handlers/reflect-config\.json --exclude-config io\.netty\.netty-handler /META-INF/native-image/io\.netty/netty-handler/generated/handlers/reflect-config\.json getting-started-1.0.0-SNAPSHOT-runner -jar getting-started-1.0.0-SNAPSHOT-runner.jar
Warning: Option 'DynamicProxyConfigurationResources' is deprecated and might be removed in a future release: This can be caused by a proxy-config.json file in your META-INF directory. Consider including proxy configuration in the reflection section of reachability-metadata.md instead.. Please refer to the GraalVM release notes.
========================================================================================================================
GraalVM Native Image: Generating 'getting-started-1.0.0-SNAPSHOT-runner' (executable)...
========================================================================================================================
[1/8] Initializing...                                                                                    (3.9s @ 0.31GB)
 Java version: 24-beta+15-ea, vendor version: Mandrel-24.2.0-dev
 Graal compiler: optimization level: 2, target machine: x86-64-v3
 C compiler: gcc (redhat, x86_64, 13.3.1)
 Garbage collector: Serial GC (max heap size: 80% of RAM)
 3 user-specific feature(s):
 - com.oracle.svm.thirdparty.gson.GsonFeature
 - io.quarkus.runner.Feature: Auto-generated class by Quarkus from the existing extensions
 - io.quarkus.runtime.graal.DisableLoggingFeature: Disables INFO logging during the analysis phase
------------------------------------------------------------------------------------------------------------------------
 4 experimental option(s) unlocked:
 - '-H:+AllowFoldMethods' (origin(s): command line)
 - '-H:BuildOutputJSONFile' (origin(s): command line)
 - '-H:-UseServiceLoaderFeature' (origin(s): command line)
 - '-H:+GenerateBuildArtifactsFile' (origin(s): command line)
------------------------------------------------------------------------------------------------------------------------
Build resources:
 - 26.49GB of memory (42.4% of 62.55GB system memory, determined at start)
 - 12 thread(s) (100.0% of 12 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/sgehwolf/Documents/openjdk/quarkus/quarkus-quickstarts/getting-started/target/getting-started-1.0.0-SNAPSHOT-native-image-source-jar/lib/com.aayushatharva.brotli4j.brotli4j-1.16.0.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

*****]                                                                   (19.1s @ 0.98GB)
   11,206 reachable types   (85.2% of   13,160 total)
   15,854 reachable fields  (49.3% of   32,167 total)
   56,459 reachable methods (55.6% of  101,576 total)
    3,601 types,    15 fields, and   999 methods registered for reflection
       62 types,    67 fields, and    55 methods registered for JNI access
        4 native libraries: dl, pthread, rt, z
[3/8] Building universe...                                                                               (3.5s @ 1.18GB)
[4/8] Parsing methods...      [**]                                                                       (2.4s @ 1.28GB)
[5/8] Inlining methods...     [***]                                                                      (1.5s @ 1.40GB)
[6/8] Compiling methods...    [****]                                                                    (20.3s @ 1.01GB)
[7/8] Laying out methods...   [**]                                                                       (3.9s @ 1.34GB)
[8/8] Creating image...       [**]                                                                       (3.7s @ 1.52GB)
  23.07MB (47.31%) for code area:    36,374 compilation units
  25.00MB (51.26%) for image heap:  304,813 objects and 66 resources
 712.58kB ( 1.43%) for other data
  48.77MB in total
------------------------------------------------------------------------------------------------------------------------
Top 10 origins of code area:                                Top 10 object types in image heap:
  12.91MB java.base                                            6.35MB byte[] for code metadata
   1.76MB svm.jar (Native Image)                               3.91MB byte[] for java.lang.String
   1.10MB getting-started-1.0.0-SNAPSHOT-runner.jar            2.80MB java.lang.Class
 945.70kB modified-io.vertx.vertx-core-4.5.10.jar              2.73MB java.lang.String
 559.62kB io.netty.netty-buffer-4.1.111.Final.jar              1.06MB byte[] for general heap data
 491.66kB io.netty.netty-common-4.1.111.Final.jar            963.02kB com.oracle.svm.core.hub.DynamicHubCompanion
 415.66kB io.netty.netty-codec-http-4.1.111.Final.jar        667.02kB byte[] for reflection metadata
 383.70kB io.netty.netty-codec-http2-4.1.111.Final.jar       537.61kB java.lang.String[]
 375.50kB io.netty.netty-transport-4.1.111.Final.jar         489.80kB java.util.HashMap$Node
 369.26kB io.smallrye.config.smallrye-config-core-3.9.1.jar  405.51kB c.o.svm.core.hub.DynamicHub$ReflectionMetadata
   3.58MB for 76 more packages                                 5.16MB for 2827 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.
------------------------------------------------------------------------------------------------------------------------
                        3.9s (6.4% of total time) in 749 GCs | Peak RSS: 2.27GB | CPU load: 9.49
------------------------------------------------------------------------------------------------------------------------
Build artifacts:
 /home/sgehwolf/Documents/openjdk/quarkus/quarkus-quickstarts/getting-started/target/getting-started-1.0.0-SNAPSHOT-native-image-source-jar/build-artifacts.json (build_info)
 /home/sgehwolf/Documents/openjdk/quarkus/quarkus-quickstarts/getting-started/target/getting-started-1.0.0-SNAPSHOT-native-image-source-jar/getting-started-1.0.0-SNAPSHOT-runner (executable)
 /home/sgehwolf/Documents/openjdk/quarkus/quarkus-quickstarts/getting-started/target/getting-started-1.0.0-SNAPSHOT-native-image-source-jar/getting-started-1.0.0-SNAPSHOT-runner-build-output-stats.json (build_info)
========================================================================================================================
Finished generating 'getting-started-1.0.0-SNAPSHOT-runner' in 60.0s.
[INFO] [io.quarkus.deployment.pkg.steps.NativeImageBuildRunner] objcopy --strip-debug getting-started-1.0.0-SNAPSHOT-runner
[INFO] [io.quarkus.deployment.QuarkusAugmentor] Quarkus augmentation completed in 63493ms
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  01:11 min
[INFO] Finished at: 2024-09-26T17:50:21+02:00
[INFO] ------------------------------------------------------------------------

Expected behavior

No warning from brotli when generating the native image.

Actual behavior

A warning is produced

How to Reproduce?

  1. Get an EA build of mandrel using JDK 24. Example from our CI: https://github.com/graalvm/mandrel/actions/runs/11062379776/artifacts/1985249318
  2. Use it to compile a quickstart to native.
  3. Observe the warning.

Output of uname -a or ver

Linux x86_64

Output of java -version

JDK 24+15

Quarkus version or git rev

main

Build tool (ie. output of mvnw --version or gradlew --version)

maven

Additional information

There seem to be at least two options moving forward:

  1. Possibly get rid of the explicit brotli dependency (not sure if that'll work).
  2. Add --enable-native-access=ALL-UNNAMED to the native image build
@jerboaa jerboaa added the kind/bug Something isn't working label Sep 26, 2024
Copy link

quarkus-bot bot commented Sep 26, 2024

/cc @Karm (mandrel), @cescoffier (netty), @franz1981 (netty), @galderz (mandrel), @jponge (netty), @zakkak (mandrel)

@jerboaa
Copy link
Contributor Author

jerboaa commented Sep 26, 2024

There is this tid-bit on the codebase:

<!--
The recent version of Netty have a hard dependency on brotli,
without this dependency, it's not possible to compile to native
-->
<dependency>
<groupId>com.aayushatharva.brotli4j</groupId>
<artifactId>brotli4j</artifactId>
</dependency>
</dependencies>

@cescoffier
Copy link
Member

We will have to go with the second option.

@franz1981
Copy link
Contributor

franz1981 commented Sep 26, 2024

I'm pretty surprised that we have such hard dep -

https://github.com/search?q=repo%3Anetty%2Fnetty+brotli4j+language%3A%22Maven+POM%22&type=code&l=Maven+POM

it looks to me to be optional for the http/http2 codecs - and

image

and https://github.com/netty/netty/blob/56a91017242c57706762bd7359c921c43af64fa7/codec/src/main/java/io/netty/handler/codec/compression/StandardCompressionOptions.java#L35

looks to use an holder pattern to avoid initializing Brotli if not avaialble, too.
It looks that Brotli.isAvailable (which is something we can do something about) prevent loading the configuration options and eventually using it, so maybe there's a way to opt it out

@Karm
Copy link
Member

Karm commented Sep 26, 2024

@franz1981 It is configurable, but perfectly sane option and something expected of any contemporary webserver...

#40750

@zakkak
Copy link
Contributor

zakkak commented Sep 27, 2024

Possibly get rid of the explicit brotli dependency (not sure if that'll work).

I created #43556 to explore that possibility (to my understanding it's possible but requires some Quarkus "magic")

@zakkak
Copy link
Contributor

zakkak commented Nov 1, 2024

Although this bug was detecting using Mandrel, it's not limited to native compilation. See #44257.

Once #44257 and oracle/graal#10008 get addressed this issue should be fixed as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants