Skip to content

Re-enable sun.misc.Unsafe by default on Java 24+ #15296

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

Merged
merged 1 commit into from
May 30, 2025

Conversation

chrisvest
Copy link
Member

@chrisvest chrisvest commented May 30, 2025

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.

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.
@chrisvest chrisvest requested a review from normanmaurer May 30, 2025 17:10
@normanmaurer normanmaurer added this to the 4.1.122.Final milestone May 30, 2025
@chrisvest chrisvest merged commit 7d6b939 into netty:4.1 May 30, 2025
15 of 16 checks passed
@chrisvest chrisvest deleted the 4.1-revert-j24-unsafe branch May 30, 2025 20:36
LuciferYang pushed a commit to apache/spark that referenced this pull request Jun 11, 2025
…e to 2.0.72.Final

### What changes were proposed in this pull request?

This PR aims to Upgrade Netty to 4.1.122.Final and Netty-tcnative to 2.0.72.Final.

### Why are the changes needed?

To bring the Java 24 related update and the latest bug fixes.
> We decided to enable sun.misc.Unsafe by default again when using JDK24+ (when possible) as disabling it by default on this java versions did come with quite a performance regression.

- https://netty.io/news/2025/06/03/4-1-122-Final.html
    - netty/netty#15296
    - netty/netty#15248
    - netty/netty#15122

### 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 #51145 from dongjoon-hyun/SPARK-52438.

Authored-by: Dongjoon Hyun <dongjoon@apache.org>
Signed-off-by: yangjie01 <yangjie01@baidu.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy