Using zlib-ng
Azul Zing Builds of OpenJDK (Zing) bundle zlib-ng, a modernized, performance-optimized fork of zlib that takes advantage of instructions available on newer processors. zlib-ng is a drop-in replacement for zlib and is published under the same permissive zlib license.
By default, Zing uses the zlib implementation provided by the operating system (or the bundled libzip.so on JDK 8). When zlib-ng is enabled, Zing routes zlib API calls to the bundled zlib-ng library instead. This affects every user of zlib within the JVM process, including the java.util.zip.Inflater and java.util.zip.Deflater classes, so compression-heavy and decompression-heavy workloads can see a significant throughput improvement.
|
Note
|
-XX:+UseZlibNG is an experimental option and is disabled by default. It is available since Azul Prime 26.02.0.0 for JDK 11, 17, and 21, and cannot be enabled on JDK 25.
|
|
Caution
|
On JDK 8, -XX:+UseZlibNG is accepted without an error or a warning, but it has no effect and compression continues to use the standard zlib implementation. JDK 8 builds compile zlib directly into libzip.so rather than linking the interception library, so there is nothing for zlib-ng to replace. Do not rely on this option on JDK 8.
|
Enabling zlib-ng
Because the option is experimental, it must be used together with -XX:+UnlockExperimentalVMOptions:
java -XX:+UnlockExperimentalVMOptions -XX:+UseZlibNG -jar myapp.jar
To confirm that the option is active, print the final flag values:
java -XX:+UnlockExperimentalVMOptions -XX:+UseZlibNG -XX:+PrintFlagsFinal -version | grep UseZlibNG
Limitations and considerations
-
An LD_PRELOADed zlib takes precedence. If a zlib implementation is loaded with
LD_PRELOAD, that implementation is used regardless of-XX:+UseZlibNG. This is intended behavior and allows an existingLD_PRELOADsetup to keep working unchanged. -
Not all zlib symbols are intercepted. Zing intercepts the zlib API functions that are in common use. If your application’s JNI code calls a zlib API that is not intercepted, and the version of zlib on the host differs from the bundled zlib-ng, you might see incorrect results or a crash. If you encounter this, disable
-XX:+UseZlibNGto return all calls to the system zlib. -
Compressed output differs from zlib. zlib-ng is API-compatible and produces valid deflate streams, but the exact byte output for a given input and compression level is not guaranteed to be identical to that of zlib. Do not depend on byte-for-byte reproducibility of compressed data across implementations.