GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Introduce VarHandle 9 stub by franz1981 · Pull Request #15486 · netty/netty Conversation
Contributor
Motivation: Unsafe unavailability prevent some basic JIT optimizations while accessing buffers and reference counters, causing some pretty severe performance regression Modifications: Expose a VarHandle's 9 stub to enable Ja +9 to use it, if Unsafe is unavailable Result: Fixes #15485
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pull Request OverviewThis PR introduces a compile‐time VarHandle stub for Java 8 and a runtime fallback to use real VarHandle on Java 9+ when Unsafe is unavailable, restoring JIT optimizations for buffer and ref-count accesses.
Reviewed ChangesCopilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment. Show a summary per file
Comments suppressed due to low confidence (2)common/src/main/java/io/netty/util/internal/PlatformDependent.java:612
common/src/main/java/io/netty/util/internal/PlatformDependent.java:612
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsUh oh!
There was an error while loading. Please reload this page.
|
There was an error while loading. Please reload this page.
|
on with this PR, with with unsafe working i.e. which shows that |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@franz1981 there are some failing tests... PTAL |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@normanmaurer I've added another commit to handle the byte[] case too. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
5728f71 to
2fabb11
Compare
|
@normanmaurer @chrisvest I see that I could remove the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
6937238 to
c8f73b7
Compare
There was an error while loading. Please reload this page.
|
@normanmaurer I had to remove but I'm still getting some error which I cannot reproduce locally e.g. now investigating, since I see that the public void setInitialValue(T instance) { final long offset = unsafeOffset(); if (offset == -1) { Object vho = varHandleUpdater(); int initialValue = initialValue(); if (vho != null) { VarHandle vh = (VarHandle) vho; vh.set(instance, (int) initialValue); // <-------- THIS IS THE ERROR VarHandle.storeStoreFence(); } else { updater().set(instance, initialValue); } } else { PlatformDependent.safeConstructPutInt(instance, offset, initialValue()); } } which enforce the "right" type at runtime, not at compile time. At compile time the invocation is using I'll come up with a solution for that 👍 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
There's still something which is surprising: if I write a sample program (using
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
On the CI I'm still getting hit by the same error on JDK 24-25 but the signature now is @Override protected void setVarHandleRefCnt(VarHandle vh, AbstractReferenceCountedByteBuf instance, int refCnt) { vh.set(instance, refCnt); } Looking at |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
It could be that the issue comes from the fact that the
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Is it worthy to give it a shot @derklaro thanks for the suggestion - although "in theory" the stub shouldn't even be loaded and from the invocation pov (at byte level) it shouldn't matter |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
@derklaro and I believe you're right I just checked a clean example and the bytecode of a proper |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
If you go the stubbing route here, maybe it's best to just combine it with the JFR stub instead of having two modules. There might come a point where we want eg a StackWalker stub too. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
thanks for looking at it @yawkat I'm checking what I can do about it - unless you know But I agree that we would like to have a single stubs modules at this point |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@franz1981 I quickly skimmed through the jdk source and found that methods annotated with |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
good catch, making the stub method |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I've added a fix - it was a broken benchmark - now performance is as expected, see dfa88e72a908498f2f940eb7e5137c039fb952f4 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
We can leave VarHandle be for NI for now, but the new Configuration-based AIFU initialization has the same problem that NI won't be able to infer the field it belongs to. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Why? When unsafe or VarHandle won't be available it should be known statically and the updater is allocated without reflection and using constants Check the latest commit which perform the updater allocation in place |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Ahh you're right, I thought it was a local method call, not a static import. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@franz1981 so this is ready for review ? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Yep @normanmaurer now adding one condition and some doc but yep |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Generally speaking looks good and awesome work. Please add some comments / javadocs to explain why we need this
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
PTAL @normanmaurer added some docs in the varhandle stub to explain why it is how it is and what devs should do while using it |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Motivation: Unsafe unavailability prevent some basic JIT optimizations while accessing buffers and reference counters, causing some pretty severe performance regression Modifications: Expose a VarHandle's 9 stub to enable Ja +9 to use it, if Unsafe is unavailable Result: Fixes netty#15485
There was an error while loading. Please reload this page.
|
If it's ready to go it can unblock #15504 ptal @chrisvest or @normanmaurer |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Excellent work, @franz1981 👍
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks @chrisvest 🙏 so, ready to go? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@franz1981 squash and merge when happy with it |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@normanmaurer remember, right now I have disabled var handle if unsafe is there, since is a more performant option, but for io_uring maybe you still want to use it even if unsafe is available 🙏 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Yep will do once this one is merged |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Unsafe unavailability severely affect Netty 4.2 heap ByteBuf access performance
There was an error while loading. Please reload this page.