RFR: 8254078: DataOutputStream is very slow post-disabling of Biased Locking
Andrew Haley
aph at openjdk.java.net
Wed Oct 7 14:13:10 UTC 2020
On Wed, 7 Oct 2020 14:06:27 GMT, Roger Riggs <rriggs at openjdk.org> wrote:
> There is a pre-existing race condition on use of the writeBuffer.
> It is allocated per DataOutputStream but is unsynchronized.
> Only the write(byte) and write(byte[], off, len) methods are synchronized.
> Will that be/become a problem?
Hard to say. There isn't a guarantee in the specification. After my patch, writeInt is
public final void writeInt(int v) throws IOException {
writeBuffer[0] = (byte)(v >>> 24);
writeBuffer[1] = (byte)(v >>> 16);
writeBuffer[2] = (byte)(v >>> 8);
writeBuffer[3] = (byte)(v >>> 0);
out.write(writeBuffer, 0, 4);
incCount(4);
}
whereas writeLong() is
public final void writeLong(long v) throws IOException {
writeBuffer[0] = (byte)(v >>> 56);
writeBuffer[1] = (byte)(v >>> 48);
writeBuffer[2] = (byte)(v >>> 40);
writeBuffer[3] = (byte)(v >>> 32);
writeBuffer[4] = (byte)(v >>> 24);
writeBuffer[5] = (byte)(v >>> 16);
writeBuffer[6] = (byte)(v >>> 8);
writeBuffer[7] = (byte)(v >>> 0);
out.write(writeBuffer, 0, 8);
incCount(8);
}
I know there's a history of Java programmers writing to the implementation, not the specification, but ISTM that if
writeLong() can be written this way so can writeInt().
-------------
PR: https://git.openjdk.java.net/jdk/pull/542
More information about the core-libs-dev
mailing list