On Tue, 22 Nov 2022 09:29:14 GMT, Maurizio Cimadamore <[email protected]>
wrote:
>> Per Minborg has updated the pull request incrementally with one additional
>> commit since the last revision:
>>
>> Rework Acquisition
>
> src/java.base/share/classes/java/nio/Buffer.java line 827:
>
>> 825:
>> 826: @Override
>> 827: public Runnable acquireSessionOrNull(Buffer buffer,
>> boolean async) {
>
> If allocation/performance is an issue, a relatively straightforward way to
> adjust the code would be to let go of the TWR entirely. E.g. we have code
> that does this:
>
>
> Buffer b = ...
> try {
> // use buffer.address();
> } finally {
> Reference.reachabilityFence(b);
> }
>
>
> We could transform to this:
>
>
> Buffer b = ...
> acquire(b); // calls MemorySessionImpl.acquire0 if session is not null
> try {
> // use buffer.address();
> } finally {
> release(b); // calls MemorySessionImpl.release0 if session is not null
> (and maybe adds a reachability fence, just in case)
> }
>
> This leads to a simpler patch that is probably easier to validate. The
> remaining IOUtil code will be using a different idiom, and perhaps we can, at
> some point, go back and make that consistent too.
The AutoCloseable experiment was interesting to try but I think you are right,
acquire try { .. } finally release would be simpler and also remove the
concerns about the performance critical code paths.
-------------
PR: https://git.openjdk.org/jdk/pull/11260