RFR: 8306308: (ch) Writer created by Channels::newWriter may lose data [v3]

Daniel Jeliński djelinski at openjdk.org
Thu Oct 19 07:50:26 UTC 2023


On Wed, 18 Oct 2023 20:40:23 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

>> Change `Channels.newWriter` to return a `Writer` created by first wrapping the `WritableByteChannel` in an `OutputStream` using `Channels.newOutputStream` and then wrapping the result in an `OutputStreamWriter`. With this change in place, the problems reported in the issue do not occur.
>
> Brian Burkhalter has updated the pull request incrementally with one additional commit since the last revision:
> 
>   8306308: Add some code to dispense with lock

This is benchmarking disk access. Use a blackhole channel instead:

    public void create(Blackhole bh) throws IOException {
        cbuf = new char[capacity];
        Arrays.fill(cbuf, (char)42);
        WritableByteChannel fc = new WritableByteChannel() {
            @Override
            public int write(ByteBuffer src) throws IOException {
                bh.consume(src);
                int remaining = src.remaining();
                src.position(src.limit());
                return remaining;
            }
            @Override
            public boolean isOpen() {
                return true;
            }
            @Override
            public void close() throws IOException {
            }
        };
        writer = Channels.newWriter(fc, "UTF-8");
    }

Before:

Benchmark               (capacity)   Mode  Cnt     Score     Error   Units
WriterBench.testMethod        4096  thrpt   30  7679,273 � 111,851  ops/ms
WriterBench.testMethod        8192  thrpt   30  4194,707 �  47,489  ops/ms
WriterBench.testMethod       16384  thrpt   30  2191,705 �  46,152  ops/ms
WriterBench.testMethod       32768  thrpt   30  1040,875 �  54,422  ops/ms

After:

Benchmark               (capacity)   Mode  Cnt     Score     Error   Units
WriterBench.testMethod        4096  thrpt   30  7414,422 � 156,937  ops/ms
WriterBench.testMethod        8192  thrpt   30  4161,465 � 116,885  ops/ms
WriterBench.testMethod       16384  thrpt   30  2387,347 �  37,324  ops/ms
WriterBench.testMethod       32768  thrpt   30  1168,550 �  35,374  ops/ms

(well, still no difference)

-------------

PR Comment: https://git.openjdk.org/jdk/pull/16207#issuecomment-1770252093


More information about the nio-dev mailing list