On Tue, 12 Jan 2021 15:48:18 GMT, Maurizio Cimadamore <mcimadam...@openjdk.org> wrote:
> When support for shared segment was added, we decided to disable support for > buffers derived from shared segment in certain async operations, as there's > currently no way to make sure that the memory won't be reclaimed while the IO > operation is still taking place. > > After looking at the code, it seemed like the best place to put the > restriction would be sun.nio.ch.DirectBuffer::address() method, since this > method is used in a lot of places just before jumping into some piece of JNI > code. > > While I still stand by that decision, the Netty team has discovered that this > decision also affected operations such as creating slices from byte buffers > derived from shared segment - this is caused by the fact that one direct > buffer constructor (the one for views and slices) is calling the dreaded > DirectBuffer::address method. > > The fix is simple: just avoid the method call - which is very easy to do in > the case of the buffer constructor: in fact this method just returns the > value of the `address` field inside the `Buffer` class, so we can always cast > to `Buffer` and then access `address` field from there. This pull request has now been integrated. Changeset: 17b4db31 Author: Maurizio Cimadamore <mcimadam...@openjdk.org> URL: https://git.openjdk.java.net/jdk16/commit/17b4db31 Stats: 11 lines in 2 files changed: 9 ins; 1 del; 1 mod 8259636: Check for buffer backed by shared segment kicks in in unexpected places Reviewed-by: sundar, alanb, chegar ------------- PR: https://git.openjdk.java.net/jdk16/pull/110