Repository navigation
Auto-port 5.0: Lazily instantiate VarHandle JCTools queues via holder class - #17830
Merged
Merged
Conversation
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)
✅ All tests passed ✅🏷️ Commit: 2d10921 Learn more about TestLens at testlens.app/docs. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 tojava/util/AbstractQueue. This forces the JVM verifier to loadSpscLinkedVarHandleQueueuponPlatformDependentverification. On Java 8,SpscLinkedVarHandleQueueis compiled with major version 55.0 (Java 11), resulting in anUnsupportedClassVersionError(#17685).Modifications:
*VarHandle*Queueinstantiations in PlatformDependent into a private static holder classVarHandleQueueHolder.PlatformDependent.classno longer references any*VarHandle*Queueclasses directly, preventing the JVM bytecode verifier or ASM frame recomputations from loading them during PlatformDependent class verification.hasJctoolsVarHandle()is false, soVarHandleQueueHolderis never accessed or loaded.VarHandleQueueHolderis lazily loaded on demand, retaining the fast VarHandle queue implementations.Result:
Fixes #17685 while retaining VarHandle queues on JDK 11+.