RFR: 8254078: DataOutputStream is very slow post-disabling of Biased Locking [v6]
Andrew Haley
aph at openjdk.java.net
Tue Oct 13 12:39:27 UTC 2020
> DataOutputStream is very slow post-disabling of Biased Locking. This
> was discovered when benchmarking a transaction library, which showed
> significant performance loss when moving to JDK 15. WIth some small
> changes to DataOutputStream we can get the performance back. There's a
> JMH benchmark at
> http://cr.openjdk.java.net/~aph/JDK-8254078/jmh-tests.tar
>
> Some Stream classes use very fine-grained locking.
>
> In particular, writeInt is defined like this:
>
> out.write((v >>> 24) & 0xFF);
> out.write((v >>> 16) & 0xFF);
> out.write((v >>> 8) & 0xFF);
> out.write((v >>> 0) & 0xFF);
> incCount(4);
>
> Unfortunately, ByteArrayOutputStream.write(byte) is defined like this:
>
> public synchronized void write(int b) {
> ensureCapacity(count + 1);
> buf[count] = (byte) b;
> count += 1;
> }
>
> so we acquire and release a lock for every byte that is output.
>
> For example, writing 4kb of ints goes from 17.3 us/op to 53.9 us/op when biased locking is disabled:
>
>
> +UseBiasedLocking DataOutputStreamTest.dataOutputStreamOverByteArray avgt 6 53.895 ± 5.126 us/op
> -UseBiasedLocking DataOutputStreamTest.dataOutputStreamOverByteArray avgt 6 17.291 ± 4.430 us/op
>
> There are refactorings of DataOutputStream we can do to mitigate this.
Andrew Haley has updated the pull request incrementally with one additional commit since the last revision:
8254078: DataOutputStream is very slow post-disabling of Biased Locking
-------------
Changes:
- all: https://git.openjdk.java.net/jdk/pull/542/files
- new: https://git.openjdk.java.net/jdk/pull/542/files/43be1998..cd1d5a0a
Webrevs:
- full: https://webrevs.openjdk.java.net/?repo=jdk&pr=542&range=05
- incr: https://webrevs.openjdk.java.net/?repo=jdk&pr=542&range=04-05
Stats: 18 lines in 2 files changed: 0 ins; 6 del; 12 mod
Patch: https://git.openjdk.java.net/jdk/pull/542.diff
Fetch: git fetch https://git.openjdk.java.net/jdk pull/542/head:pull/542
PR: https://git.openjdk.java.net/jdk/pull/542
More information about the core-libs-dev
mailing list