Skip to content

Skip VarHandle init when unaligned access is supported#16664

Merged
normanmaurer merged 3 commits into
netty:4.2from
Songdoeon:fix-16607-skip-varhandle-when-aligned
Apr 21, 2026
Merged

Skip VarHandle init when unaligned access is supported#16664
normanmaurer merged 3 commits into
netty:4.2from
Songdoeon:fix-16607-skip-varhandle-when-aligned

Conversation

@Songdoeon

Copy link
Copy Markdown
Contributor

Motivation

#16207 removed the UNSAFE_UNAVAILABILITY_CAUSE == null guard from initializeVarHandle(). This made VarHandle code reachable even when Unsafe is available,
causing Truffle/Polyglot native-image builds to fail with MethodHandle.linkToStatic blocklist violations (#16607).

Restoring the original Unsafe guard fixes #16607, but also kills #16207's core feature (VarHandle fallback when UNALIGNED is unknown).

Modification

Use isUnaligned() as the guard instead. On platforms where unaligned access is known (x86, modern ARM), Unsafe already handles multi-byte access fine, so VarHandle
isn't needed and VarHandleFactory stays unreachable.

On platforms where UNALIGNED is unknown (exactly the case #16207 targets), VarHandle still gets initialized and works as before.

Result

Fixes #16607.

Tested with the reporter's project (https://github.com/adamdickmeiss/vertx-graalvm-native-image-log4j):

  • Before: === Found 4 compilation blocklist violations === BUILD FAILURE
  • After: No violations, BUILD SUCCESS

@chrisvest chrisvest added this to the 4.2.13.Final milestone Apr 21, 2026
@chrisvest chrisvest added the needs-cherry-pick-5.0 This PR should be cherry-picked to 5.0 once merged. label Apr 21, 2026
@normanmaurer normanmaurer merged commit 6b16cda into netty:4.2 Apr 21, 2026
17 of 19 checks passed
@netty-project-bot

Copy link
Copy Markdown
Contributor

Could not create auto-port PR.
Got conflicts when cherry-picking onto 5.0.

@normanmaurer

Copy link
Copy Markdown
Member

PR for 5.0 #16676

normanmaurer added a commit that referenced this pull request Apr 21, 2026
`initializeVarHandle()`. This made VarHandle code reachable even when
Unsafe is available,
causing Truffle/Polyglot native-image builds to fail with
`MethodHandle.linkToStatic` blocklist violations (#16607).
Restoring the original Unsafe guard fixes #16607, but also kills

Use `isUnaligned()` as the guard instead. On platforms where unaligned
access is known (x86, modern ARM), Unsafe already handles multi-byte
access fine, so VarHandle
   isn't needed and VarHandleFactory stays unreachable.
On platforms where UNALIGNED is unknown (exactly the case #16207
targets), VarHandle still gets initialized and works as before.

Fixes #16607.

Tested with the reporter's project
(https://github.com/adamdickmeiss/vertx-graalvm-native-image-log4j):
- Before: `=== Found 4 compilation blocklist violations ===` BUILD
FAILURE
- After: No violations, BUILD SUCCESS

Co-authored-by: Chris Vest <christianvest_hansen@apple.com>

Co-authored-by: DoeonSong <96420547+Songdoeon@users.noreply.github.com>
Co-authored-by: Chris Vest <christianvest_hansen@apple.com>
@chrisvest chrisvest removed the needs-cherry-pick-5.0 This PR should be cherry-picked to 5.0 once merged. label Apr 21, 2026
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.

Native image blocklist violations, Netty 4.2.11/12 regression, Polyglot (JS)

4 participants