Skip to content

feat: conditionally disable netty unsafe to leverage the ffm api#1664

Merged
derklaro merged 5 commits into
nightlyfrom
conditional-netty-no-unsafe
Jun 29, 2025
Merged

feat: conditionally disable netty unsafe to leverage the ffm api#1664
derklaro merged 5 commits into
nightlyfrom
conditional-netty-no-unsafe

Conversation

@derklaro

@derklaro derklaro commented Jun 20, 2025

Copy link
Copy Markdown
Member

Motivation

In netty 4.2.3 a new type of ByteBuffer cleaner (or allocator) will be introduced that uses malloc and free directly using the ffm api on java 24+. In order to enable this cleaner, unsafe has to be unavailable/disabled. Since this can be a performance issue (as the ByteBuffer lifecycle might be controlled by the garbage collector if unsafe is unavailable) we only disable unsafe when the new cleaner implementation is available.

Modification

Add a transformer that checks if all conditions are met to disable unsafe in order to enable the ffm-based cleaner implementation. If that is the case, the PlatformDependent0#explicitNoUnsafeCause0() method will be overridden to always return an UOE to indicate that unsafe is explicitly disabled.

Result

On netty 4.2.3+ unsafe will be disabled in favor of the ffm-linker based cleaner implementation, but only is all necessary preconditions to enable the cleaner are met.

@derklaro derklaro added this to the 4.0.0-RC13 milestone Jun 20, 2025
@derklaro derklaro requested a review from 0utplay June 20, 2025 22:19
@derklaro derklaro self-assigned this Jun 20, 2025
@derklaro derklaro added v: 4.X This pull should be included in the 4.0 release t: improvement The pull request improves existing code in: wrapper An issue/pull request releated to the wrapper module code labels Jun 20, 2025
@github-actions

github-actions Bot commented Jun 20, 2025

Copy link
Copy Markdown

Test Results

 56 files  ±0   56 suites  ±0   2m 24s ⏱️ -9s
566 tests ±0  566 ✅ ±0  0 💤 ±0  0 ❌ ±0 
931 runs  ±0  931 ✅ ±0  0 💤 ±0  0 ❌ ±0 

Results for commit 3488619. ± Comparison against base commit e4d1f49.

♻️ This comment has been updated with latest results.

0utplay
0utplay previously approved these changes Jun 22, 2025
0utplay
0utplay previously approved these changes Jun 28, 2025
@derklaro derklaro merged commit 5c85c01 into nightly Jun 29, 2025
5 checks passed
@derklaro derklaro deleted the conditional-netty-no-unsafe branch June 29, 2025 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: wrapper An issue/pull request releated to the wrapper module code t: improvement The pull request improves existing code v: 4.X This pull should be included in the 4.0 release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants