-
Notifications
You must be signed in to change notification settings - Fork 320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improves MessageBuffer support for Java 11 #514
Conversation
Switches the MessageBuffer implementation to MessageBufferU for Java versions at least 9. Since this implementation overrides almost all MessageBuffer's method it is safe to allow direct buffers as argument to MessageBuffer.wrap(ByteBuffer)
msgpack-core/src/main/java/org/msgpack/core/buffer/MessageBuffer.java
Outdated
Show resolved
Hide resolved
@ppkarwasz Thanks for the suggestions. Unfortunately, however, using MessageBufferU for Java 9 or later cannot be our option as it will have a significant impact on the performance. We need to find a way to make DirectBufferAccess work on jdk9 or later. |
Disables the automatic switch to MessageBufferU on Java 9+, falling back to a manual switch through Java properties.
Java 11 tests without the "msgpack.universal-buffer" property set where using the universal buffer anyway: Java 11's "java.specification.version" does not contain a dot, so MessageBuffer misidentified it as Java less than 7 and switched to MessageBufferU.
I removed the automatic switch to With these last changes this PR may still serve a purpose: the original code throws an exception, when we instantiate a In our use case the support for direct buffers is essential: we feed |
I might adapt netty-common's solution to the |
@ppkarwasz Yes. We also use netty or jetty-provided ByteBuffer with msgpack. What is netty-common's approach for supporting jdk9? If it's reasonable, I'd like to use it in this PR instead of ignoring jdk11 test for MessageBuffer. |
In Java 9+ |
For Java 9+ we switch from a DirectByteBuffer.cleaner().clean() call to Unsafe.invokeCleaner(buffer).
Adds missing setAccessible calls.
Done. Now it should work on both Java 8 and Java 11. Summarizing, this PR:
|
@ppkarwasz Thanks for your work. We will take over the remaining task (if necessary) as we also need to support Java11. (cc: @miniway) |
It looks very good to me. Also we could encapsulate the Cleaner in a separate class in the future |
It also looks good to me. Let me merge it and release a new version. |
Switches the MessageBuffer implementation to MessageBufferU for Java versions at least 9, which solves a couple of problems:
Since MessageBufferU overrides almost all methods of MessageBuffer, while direct ByteBuffers register a cleaner by themself, I don't see why MessageBufferU(ByteBuffer) shouldn't accept direct buffers.
This should also solve bug number #482.