8358537: (bf) JavaNioAccess::getBufferAddress bypasses direct buffer MemorySession state check#25631
8358537: (bf) JavaNioAccess::getBufferAddress bypasses direct buffer MemorySession state check#25631bplb wants to merge 2 commits into
Conversation
…MemorySession state check
|
|
|
👋 Welcome back bpb! A progress list of the required criteria for merging this PR into |
|
❗ This change is not yet ready to be integrated. |
Webrevs
|
|
Discussed this with the rest of the Panama team. The way it works currently (without this PR) is how it's intended to work. The issue is that JDK code can take the address of a direct byte buffer and pass it to some native method, but if the buffer was backed by a shared arena, the memory can be freed in the middle of that. That's why the 'default' implementation in As for heap buffers: The base object and address form an Unsafe addressing pair. i.e. these are passed to Unsafe accessor methods. For heap buffers this would be the array base offset + any offset into the array (in bytes). The implementation of e.g. |
Thank you for the elucidation: that is very helpful. Perhaps some comments need to be added in strategic places to clarify the situation to avoid similar confusion in the future? This PR arose out of #25531, in particular when it was suggested to access the address of the direct buffer via |
It would be all right to repurpose this PR and its issue simply to add such comments. |
I think we should start by reviewing the test coverage. The channels/etc/MemorySegments.java test that we added will exercise all the methods on the synchronous channels that take a ByteBuffer as a parameter. We need to check what tests we have for AsynchronousSocketChannel and AsynchronousFileChannel to ensure that we are testing them with buffers that are views of memory segments allocated from an auto or the global arena. We need good tests before changing anything. |
|
The test in #25531 covers |
|
The corresponding issue was closed as Not an Issue so this request is being withdrawn. |
Add package-scope
long java.nio.Buffer::address()to simply return the value of theaddressinstance variable; use this method inJavaNioAccess::getBufferAddress.Progress
Issue
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/25631/head:pull/25631$ git checkout pull/25631Update a local copy of the PR:
$ git checkout pull/25631$ git pull https://git.openjdk.org/jdk.git pull/25631/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 25631View PR using the GUI difftool:
$ git pr show -t 25631Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/25631.diff
Using Webrev
Link to Webrev Comment