RFR: 8330748: ByteArrayOutputStream.writeTo(OutputStream) pins carrier [v2]

Brian Burkhalter bpb at openjdk.org
Wed Apr 24 15:45:58 UTC 2024


On Wed, 24 Apr 2024 14:54:34 GMT, Viktor Klang <vklang at openjdk.org> wrote:

>> Currently we have
>> 
>>     public void writeTo(OutputStream out) throws IOException {
>>         if (Thread.currentThread().isVirtual()) {
>>             out.write(toByteArray());
>>         } else synchronized (this) {
>>             out.write(buf, 0, count);
>>         }
>>     }
>> 
>> where `toByteArray()` is `synchronized`, but here I would think that we'd want to replace it with simply `Arrays.copyOf(buf, count)` without the `synchronized`, no?
>
> @bplb My interpretation was that we didn't want to hold the monitor *during* out.write().

Please see 8076291fb3d097ef67d0b59b9be3c8b762aad7cf.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/18901#discussion_r1578116805


More information about the core-libs-dev mailing list