Repository navigation
Disable sun.misc.Unsafe by default on Java 24+ - #14943
Conversation
Motivation: Java 24 has started to print warnings when `sub.misc.Unsafe` is used to access memory. See JEP 498: https://openjdk.org/jeps/498 People tend to be sensitive to new warnings and errors printed by the JVM, so we should avoid enabling `Unsafe` by default on Java 24 onwards. Modification: Effectively change the default value of the `io.netty.noUnsafe` system property for Java 24 onwards, but in a way where we can tell if it was explicitly set to a given value or if it follows the default. Any sort of explicit settings, be it `-Dio.netty.noUnsafe=false` or `--sun-misc-unsafe-memory-access=allow`, will continue to work as before. Manually verified that the changes work as intended on Java 24. Result: No more warnings printed to the console on Java 24+. Fixes netty#14942
458559d to
b0f617b
Compare
|
Since not using Unsafe has some relevant performance effect, switching its usage off by default isn't too much? |
And if it does. We should log at |
We won't have much choice in future java versions. For the time being, the command line flag allow people to keep using Unsafe.
Many teams are more sensitive to new log messages than they are to performance. If people investigate a change in performance after upgrading their Java version, they might notice the debug log message explaining the changed default. |
Motivation: Java 24 has started to print warnings when `sub.misc.Unsafe` is used to access memory. See JEP 498: https://openjdk.org/jeps/498 People tend to be sensitive to new warnings and errors printed by the JVM, so we should avoid enabling `Unsafe` by default on Java 24 onwards. Modification: Effectively change the default value of the `io.netty.noUnsafe` system property for Java 24 onwards, but in a way where we can tell if it was explicitly set to a given value or if it follows the default. Any sort of explicit settings, be it `-Dio.netty.noUnsafe=false` or `--sun-misc-unsafe-memory-access=allow`, will continue to work as before. Manually verified that the changes work as intended on Java 24. Result: No more warnings printed to the console on Java 24+. Fixes #14942
JEP-498 mentions replacement standard APIs. Do those have nothing close that can give similar performance? Is it a matter of adapting the code? |
|
It's code adaptation. If we were to use the Foreign Function and Memory APIs, we'd have to make a lot of changes to support it, as the APIs are very far from how you use Unsafe. And FFM is only available from Java 22. We will instead be making those changes in the |
Motivation: Java 24 has started to print warnings when `sub.misc.Unsafe` is used to access memory. See JEP 498: https://openjdk.org/jeps/498 People tend to be sensitive to new warnings and errors printed by the JVM, so we should avoid enabling `Unsafe` by default on Java 24 onwards. Modification: Effectively change the default value of the `io.netty.noUnsafe` system property for Java 24 onwards, but in a way where we can tell if it was explicitly set to a given value or if it follows the default. Any sort of explicit settings, be it `-Dio.netty.noUnsafe=false` or `--sun-misc-unsafe-memory-access=allow`, will continue to work as before. Manually verified that the changes work as intended on Java 24. Result: No more warnings printed to the console on Java 24+. Fixes #14942 Co-authored-by: Chris Vest <[email protected]>
Netty uses Unsafe in some cases which causes warnings in JDK24 See https://openjdk.org/jeps/498 For now continue to use it due to performance impacts. See discussion in netty/netty#14943
Netty uses Unsafe in some cases which causes warnings in JDK24 See https://openjdk.org/jeps/498 For now continue to use it due to performance impacts. See discussion in netty/netty#14943
Netty uses Unsafe in some cases which causes warnings in JDK24 See https://openjdk.org/jeps/498 For now continue to use it due to performance impacts. See discussion in netty/netty#14943
### What changes were proposed in this pull request? This PR aims to Upgrade Netty to 4.1.121.Final. ### Why are the changes needed? To support Java 24+ more easily and bring the latest bug fixes. - https://netty.io/news/2025/04/23/4-1-120-Final.html - netty/netty#14943 - netty/netty#15035 - https://netty.io/news/2025/04/24/4-1-121-Final.html ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Pass the CIs. ### Was this patch authored or co-authored using generative AI tooling? No. Closes #50749 from dongjoon-hyun/SPARK-51944. Authored-by: Dongjoon Hyun <[email protected]> Signed-off-by: Kent Yao <[email protected]>
Motivation: In netty#14943 we disabled Unsafe by default on Java 24+, to avoid producing warnings from the JVM. However, disabling the use of Unsafe also disables the hacks we use to access `ByteBuffer` cleaners to eagerly deallocate them. This can have dire performance consequences, particularly for busy applications. Disabling the warnings from Unsafe also did nothing to stem the warnings produced by our JNI code, so many systems still see warnings anyway. We should instead revert the changed default, and just tolerate the warning in Netty 4.1. In Netty 4.2 we have netty#15231 as a long-term fix, where we avoid using Unsafe but will have a way to eagerly release the memory of our native ByteBuffer instances. Modification: Change the default for our Unsafe usage to no longer be disabled on Java 24+. Result: More consistent performance across Java versions.
See https://github.com/netty/netty/wiki/Java-24-and-sun.misc.Unsafe for more information. Motivation: In #14943 we disabled Unsafe by default on Java 24+, to avoid producing warnings from the JVM. However, disabling the use of Unsafe also disables the hacks we use to access `ByteBuffer` cleaners to eagerly deallocate them. This can have dire performance consequences, particularly for busy applications. Disabling the warnings from Unsafe also did nothing to stem the warnings produced by our JNI code, so many systems still see warnings anyway. We should instead revert the changed default, and just tolerate the warning in Netty 4.1. In Netty 4.2 we have #15231 as a long-term fix, where we avoid using Unsafe but will have a way to eagerly release the memory of our native ByteBuffer instances. Modification: Change the default for our Unsafe usage to no longer be disabled on Java 24+. Result: More consistent performance across Java versions.
|
For people following this issue, we reverted this change in #15296 because the performance regression was too much. See https://github.com/netty/netty/wiki/Java-24-and-sun.misc.Unsafe for more information. |
…ings ### What changes were proposed in this pull request? This PR aims to set `io.netty.noUnsafe` to `true` to avoid JEP-498 warnings. ### Why are the changes needed? Java 24 has started to print warnings when `sub.misc.Unsafe` is used to access memory. - https://openjdk.org/jeps/498 Since Netty 4.1.120.Final, we can use `io.netty.noUnsafe` setting. - netty/netty#14943 ### Does this PR introduce _any_ user-facing change? No behavior change. ### How was this patch tested? Manually tests. **BEFORE** ``` Starting Operator... WARNING: A terminally deprecated method in sun.misc.Unsafe has been called WARNING: sun.misc.Unsafe::allocateMemory has been called by io.netty.util.internal.PlatformDependent0$2 (file:/opt/spark-operator/operator/spark-kubernetes-operator.jar) WARNING: Please consider reporting this to the maintainers of class io.netty.util.internal.PlatformDependent0$2 WARNING: sun.misc.Unsafe::allocateMemory will be removed in a future release 25/10/09 03:35:46 INFO o.a.s.k.o.SparkOperator Configuring operator with 50 reconciliation threads. ``` **AFTER** ``` Starting Operator... 25/10/09 03:32:21 INFO o.a.s.k.o.SparkOperator Configuring operator with 50 reconciliation threads. ``` ### Was this patch authored or co-authored using generative AI tooling? No. Closes #378 from dongjoon-hyun/SPARK-53851. Authored-by: Dongjoon Hyun <[email protected]> Signed-off-by: Dongjoon Hyun <[email protected]>
This PR aims to Upgrade Netty to 4.1.121.Final. To support Java 24+ more easily and bring the latest bug fixes. - https://netty.io/news/2025/04/23/4-1-120-Final.html - netty/netty#14943 - netty/netty#15035 - https://netty.io/news/2025/04/24/4-1-121-Final.html No. Pass the CIs. No. Closes apache#50749 from dongjoon-hyun/SPARK-51944. Authored-by: Dongjoon Hyun <[email protected]> Signed-off-by: Kent Yao <[email protected]>
This PR aims to Upgrade Netty to 4.1.121.Final. To support Java 24+ more easily and bring the latest bug fixes. - https://netty.io/news/2025/04/23/4-1-120-Final.html - netty/netty#14943 - netty/netty#15035 - https://netty.io/news/2025/04/24/4-1-121-Final.html No. Pass the CIs. No. Closes apache#50749 from dongjoon-hyun/SPARK-51944. Authored-by: Dongjoon Hyun <[email protected]> Signed-off-by: Kent Yao <[email protected]>
This PR aims to Upgrade Netty to 4.1.121.Final. To support Java 24+ more easily and bring the latest bug fixes. - https://netty.io/news/2025/04/23/4-1-120-Final.html - netty/netty#14943 - netty/netty#15035 - https://netty.io/news/2025/04/24/4-1-121-Final.html No. Pass the CIs. No. Closes apache#50749 from dongjoon-hyun/SPARK-51944. Authored-by: Dongjoon Hyun <[email protected]> Signed-off-by: Kent Yao <[email protected]>
This PR aims to Upgrade Netty to 4.1.121.Final. To support Java 24+ more easily and bring the latest bug fixes. - https://netty.io/news/2025/04/23/4-1-120-Final.html - netty/netty#14943 - netty/netty#15035 - https://netty.io/news/2025/04/24/4-1-121-Final.html No. Pass the CIs. No. Closes apache#50749 from dongjoon-hyun/SPARK-51944. Authored-by: Dongjoon Hyun <[email protected]> Signed-off-by: Kent Yao <[email protected]>
Warning
Without access to
sun.misc.Unsafe, Netty is unable to eagerly free directByteBufferinstances, and instead has to rely on the garbage collector and reference processing.This delays the freeing of unused memory, and can cause greatly increase the memory usage of busy systems.
To revert the Netty behavior and permit it to eagerly free memory, apply one of the following settings to your JVM command line:
--sun-misc-unsafe-memory-access=allow(preferred)-Dio.netty.noUnsafe=false(may or may not work for shaded libraries)Alternatively, upgrade to Netty 4.2 where we are able to apply a long-term work-around.
See https://github.com/netty/netty/wiki/Java-24-and-sun.misc.Unsafe for more information.
Motivation:
Java 24 has started to print warnings when
sub.misc.Unsafeis used to access memory. See JEP 498: https://openjdk.org/jeps/498People tend to be sensitive to new warnings and errors printed by the JVM, so we should avoid enabling
Unsafeby default on Java 24 onwards.Modification:
Effectively change the default value of the
io.netty.noUnsafesystem property for Java 24 onwards, but in a way where we can tell if it was explicitly set to a given value or if it follows the default.Any sort of explicit settings, be it
-Dio.netty.noUnsafe=falseor--sun-misc-unsafe-memory-access=allow, will continue to work as before.Manually verified that the changes work as intended on Java 24.
Result:
No more warnings printed to the console on Java 24+.
Fixes #14942