Skip to content

Auto-port 5.0: Lazily instantiate VarHandle JCTools queues via holder class - #17830

Merged
normanmaurer merged 1 commit into
5.0from
auto-port-pr-17750-to-5.0
Oct 15, 2026
Merged

normanmaurer merged 1 commit into
5.0from
auto-port-pr-17750-to-5.0

Conversation

@netty-project-bot

Copy link
Copy Markdown
Contributor

Auto-port of #17750 to 5.0
Cherry-picked commit: 103787e


Motivation:

In #17185, jctools-core-jdk11 was added and shaded into netty-common to provide VarHandle-based queues when Unsafe is disabled. However, when bytecode instrumentation tools or agents (e.g. APM agents using ASM COMPUTE_FRAMES) process PlatformDependent, the branch merge of hasJctoolsVarHandle() ? new SpscLinkedVarHandleQueue<T>() : new SpscLinkedAtomicQueue<T>() causes the stack map frame to be recomputed to java/util/AbstractQueue. This forces the JVM verifier to load SpscLinkedVarHandleQueue upon PlatformDependent verification. On Java 8, SpscLinkedVarHandleQueue is compiled with major version 55.0 (Java 11), resulting in an UnsupportedClassVersionError (#17685).

Modifications:

  • Move all *VarHandle*Queue instantiations in PlatformDependent into a private static holder class VarHandleQueueHolder.
  • PlatformDependent.class no longer references any *VarHandle*Queue classes directly, preventing the JVM bytecode verifier or ASM frame recomputations from loading them during PlatformDependent class verification.
  • On Java 8 runtimes, hasJctoolsVarHandle() is false, so VarHandleQueueHolder is never accessed or loaded.
  • On Java 11+ runtimes when Unsafe is disabled, VarHandleQueueHolder is lazily loaded on demand, retaining the fast VarHandle queue implementations.

Result:

Fixes #17685 while retaining VarHandle queues on JDK 11+.

Motivation:

In #17185, jctools-core-jdk11 was added and shaded into netty-common to
provide VarHandle-based queues when Unsafe is disabled. However, when
bytecode instrumentation tools or agents (e.g. APM agents using ASM
COMPUTE_FRAMES) process PlatformDependent, the branch merge of
`hasJctoolsVarHandle() ? new SpscLinkedVarHandleQueue<T>() : new
SpscLinkedAtomicQueue<T>()` causes the stack map frame to be recomputed
to `java/util/AbstractQueue`. This forces the JVM verifier to load
`SpscLinkedVarHandleQueue` upon `PlatformDependent` verification. On
Java 8, `SpscLinkedVarHandleQueue` is compiled with major version 55.0
(Java 11), resulting in an `UnsupportedClassVersionError` (#17685).

Modifications:

- Move all `*VarHandle*Queue` instantiations in PlatformDependent into a
private static holder class `VarHandleQueueHolder`.
- `PlatformDependent.class` no longer references any `*VarHandle*Queue`
classes directly, preventing the JVM bytecode verifier or ASM frame
recomputations from loading them during PlatformDependent class
verification.
- On Java 8 runtimes, `hasJctoolsVarHandle()` is false, so
`VarHandleQueueHolder` is never accessed or loaded.
- On Java 11+ runtimes when Unsafe is disabled, `VarHandleQueueHolder`
is lazily loaded on demand, retaining the fast VarHandle queue
implementations.

Result:

Fixes #17685 while retaining VarHandle queues on JDK 11+.

Signed-off-by: Arnab Nandy <[email protected]>
(cherry picked from commit 103787e)
@testlens-app

testlens-app Bot commented Oct 15, 2026

Copy link
Copy Markdown

✅ All tests passed ✅

🏷️ Commit: 2d10921
▶️ Tests: 30943 executed
⚪️ Checks: 13/13 completed


Learn more about TestLens at testlens.app/docs.

@normanmaurer
normanmaurer merged commit f72c6f3 into 5.0 Oct 15, 2026
14 checks passed
@normanmaurer normanmaurer added this to the 5.0.0.Final milestone Oct 15, 2026
@normanmaurer
normanmaurer deleted the auto-port-pr-17750-to-5.0 branch October 15, 2026 14:08
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.

3 participants